首页 > 解决方案 > 我试图召回第 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);
  }
}

标签: java

解决方案


你的代码有很多语法错误最好使用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

推荐阅读