java - Java if else 问题
问题描述
基本上我的代码假设通过使用高度来计算重量。用户必须在他/她是男性还是女性之间进行选择。之后,if-else 语句应该进行计算。问题是当用户键入男性或女性之间的选择时。代码忽略了选择并立即转到 else 语句来告诉您您的选择是错误的。
导入 java.util.Scanner;
公共课课{
public static void main(String[] args) {
Scanner Scan = new Scanner(System.in);
System.out.println("\nAre you Male or Female: ");
String Choice = Scan.nextLine();
if (Choice == "Male") {
System.out.println("What is your hight in CMeters: ");
int Height = Scan.nextInt();
if (Height > 160) {
int Your_weight = (Height - 100) * 90 / 100;
System.out.println("Your_weight is: " + Your_weight);
}
else {
int Your_weight = (Height - 100);
System.out.println("Your_weight is: " + Your_weight);
}
}
else if (Choice == "Female") {
System.out.println("What is your hight in CMeters: ");
int Height = Scan.nextInt();
if (Height > 160) {
int Your_weight = (Height - 100) * 90 / 100;
System.out.println("Your_weight is: " + Your_weight);
}
else {
int Your_weight = (Height - 100);
System.out.println("Your_weight is: " + Your_weight);
}
}
else {
System.out.println("you Enter a worng choice");
}
}
}
解决方案
推荐阅读
- openvino - 如何为 OpenVino 永久设置环境变量
- c++ - 如何给类添加继承结构,参考“enable_share_on_this”
- c# - UWP NavigationView 防止卸载页面
- ionic-framework - 如何在 ionic 3 pwa 应用程序中禁用 Android 后退按钮
- reactjs - 反应从 DOM 计算的初始状态
- asp.net-mvc - 将 Visual Studio 2017 从移动开发更改回 Web 开发
- node.js - 为什么 Angular CLI 不能识别当前的 Node.js 版本?
- javascript - TypeError:TypeError:null 不是对象(评估“this.state.email”)
- react-native - 在减速器中无法将所有 api 数据放在一起
- htdocs - 如何使用 php 保护 htdocs 文件?