请教一个简单的java问题,为什么我输入正确的if条件循环却不会执行,一直执行else的条件
importjava.util.Scanner;publicclassXunHuanDemoText{publicstaticvoidmain(Stringargs[])...
import java.util.Scanner;
public class XunHuanDemoText
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Please input the subject");
int score = 0;
String object = sc.nextLine();
if(object == "English")
{
score = 90;
}
else if(object == "Chinese language")
{
score = 70;
}
else if(object == "math")
{
score = 80;
}
else
{
System.out.println("mirror");
}
System.out.println(score);
}
} 展开
public class XunHuanDemoText
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Please input the subject");
int score = 0;
String object = sc.nextLine();
if(object == "English")
{
score = 90;
}
else if(object == "Chinese language")
{
score = 70;
}
else if(object == "math")
{
score = 80;
}
else
{
System.out.println("mirror");
}
System.out.println(score);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询