我对Java非常陌生,这实际上是我的第一个项目。我一直在谷歌搜索和阅读,试验和错误的事情好几天,我仍然坚持两件事。
我确信他们的问题非常简单,我觉得愚蠢,但我感到很沮丧!
1)我需要做一个由短路和&&&这将导致任何输入低于0和超过100是一个错误。但是我不知道这是怎么可能的,因为一个数字不能小于100且超过100.我错过了什么?
2)我不知道我必须做什么才能为String变量赋值'error'。我觉得这应该是超级简单但我无法理解......我只知道我不能将它作为一份印刷声明。
非常感谢您的任何意见/建议,我真的很感激!
import java.util.Scanner;
public class Project {
public static void main(String[] args) {
char letter;
Scanner input = new Scanner(System.in);
System.out.print("Please input your score.");
int score = input.nextInt();
if (score >= 90)
{
System.out.println("You have earned the letter grade: A");
}// end if for age >=90
else if (score >= 80)
{
System.out.println("You have earned the letter grade: B");
} // end else if for >=80
else
{
if (score >= 70)
{
System.out.println("You have earned the letter grade: C");
}// end if for age >=70
else
{
if (score >= 60)
{
System.out.println("You have earned the letter grade: D");
}// end if for >=60
else
{
System.out.println("You have earned the letter grade: F");
}
}
}
}
}
答案 0 :(得分:1)
1)您必须使用正确的运算符||
。
if (score < 0 || score > 100) { ... }
2)在Java中,单引号''
用于字符,双引号""
用于字符串。
String s = "error";