import java.util.Scanner; public class test3_2 { /** * @param args */ public static void main(Strin
运行不出来,为什么?求解谢谢(*^__^*)importjava.util.Scanner;publicclasstest3_2{/***@paramargs*/publ...
运行不出来,为什么?求解 谢谢(*^__^*)
import java.util.Scanner;
public class test3_2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String grade=sc.next();
if(grade=="A")
System.out.println(grade+" is 85~100");
else if(grade=="B")
System.out.println(grade+" is 70~84");
else if(grade=="C")
System.out.println(grade+" is 60~69");
else if(grade=="D")
System.out.println(grade+" is <60");
}
} 展开
import java.util.Scanner;
public class test3_2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String grade=sc.next();
if(grade=="A")
System.out.println(grade+" is 85~100");
else if(grade=="B")
System.out.println(grade+" is 70~84");
else if(grade=="C")
System.out.println(grade+" is 60~69");
else if(grade=="D")
System.out.println(grade+" is <60");
}
} 展开
展开全部
import java.util.Scanner;
public class ScannerTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String grade = sc.next();
if ("A".equals(grade))
System.out.println(grade + " is 85~100");
else if ("B".equals(grade))
System.out.println(grade + " is 70~84");
else if ("C".equals(grade))
System.out.println(grade + " is 60~69");
else if ("D".equals(grade))
System.out.println(grade + " is <60");
}
}
对象比较的时候,用equals()
顺便说一下,用 "A".equals(grade) 和 grade.equals("A"); 使用前者的形式,因为当 grade ==null 时,前者不会有异常,而后者有异常。
public class ScannerTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String grade = sc.next();
if ("A".equals(grade))
System.out.println(grade + " is 85~100");
else if ("B".equals(grade))
System.out.println(grade + " is 70~84");
else if ("C".equals(grade))
System.out.println(grade + " is 60~69");
else if ("D".equals(grade))
System.out.println(grade + " is <60");
}
}
对象比较的时候,用equals()
顺便说一下,用 "A".equals(grade) 和 grade.equals("A"); 使用前者的形式,因为当 grade ==null 时,前者不会有异常,而后者有异常。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询