java - 我试图召回第 8 行的输出,但仍然有问题
问题描述
我试图回到第 8 行,但不知道如何,对不起,我是 Java 新手。我已经尝试了很多方法,但仍然碰壁,请问我该怎么办。
package Interview;
import java.util.Scanner;
public class Interview {
public static void main(String[] args) {
System.out.println("hello,please what is your name:");
System in = scanner(System.in);
String Input=in.nextLine();
System.out.println("well then welcome to startechz "+Input);
System.out.println("Are you a male or female:");
String Input=in.nextLine();
if (Input=male)
//recall outprint from line 8
System.out.println("once again, welcome mr"+Input of Line8);
else {
System.out.println("once again,welcome mrs"+Input of Line8);
}
}
解决方案
你的代码有很多语法错误最好使用ide
改变这个
System in = scanner(System.in);
至
Scanner in = new Scanner(System.in);
您不能再次重新定义相同的变量,您必须声明
看起来像这样
String Input=in.nextLine();
要解决这个问题,要么使用这个
String newInput=in.nextLine();
或者只是为同一个变量分配新值(当然,如果您不想再次使用旧变量),就像这样
Input=in.nextLine();
在java中比较值你使用double = sign like
Input==male
单个 = 用于分配值,例如 int value = 5;
您可以仅将 == 与原始类型一起使用,但对于引用类型,它将不起作用,因为在您的情况下,您将 String 与引用类型一起使用
为什么它不适用于引用类型,因为它将比较引用地址(内存中对象的地址(准确地说它不是物理地址,而是这样想的))
所以使用相等的方法
喜欢
if (Input.equals("male")) // you forget also to make male as string you forget the double quotations
推荐阅读
- sql - Group by 子句 - 只有第一个“组行”填充了值
- php - 加入呼叫表以按起点和终点分组
- javascript - React.js 与 ASP MVC 与 create-react-app 集成
- c# - 从 HttpRequest 获取文件名
- sql - 如何在 Django 中实现 Where Exists?
- sql-server - 仅返回联接表中具有最新日期的行
- python - numpy数组中的不同元素数据类型?
- java - 通过 @Autowired 实例化的 Spring 类 - 引用时生成空指针豁免
- pandas - 如何在文档字符串中指定 Pandas DataFrame 架构/结构?
- bluetooth - 是否可以使用 PC 来控制 Nintendo Switch 的乐趣?