【发布时间】:2020-01-28 05:53:16
【问题描述】:
我什至不知道从哪里开始解决这个问题,我必须获取一个可以在足球比赛中获得的分数,然后有一个方法将这个分数转换为主要的字符串。
代码如下:
public static void main(String[] args) {
int correctCount = 0;
if (translateScore(2).equals("safety") == true) { correctCount++;}
if (translateScore(3).equals("field goal") == true) { correctCount++;}
if (translateScore(6).equals("touchdown") == true) { correctCount++;}
if (translateScore(7).equals("touchdown and extra point") == true) { correctCount++;}
if (translateScore(8).equals("touchdown and 2-point conversion") == true) { correctCount++;}
if (translateScore(-1).equals("") == true) { correctCount++;}
if (translateScore(1).equals("invalid") == true) { correctCount++;}
if (translateScore(10).equals("you must be playing Quidditch ") == true) { correctCount++;}
if (correctCount == 8) {
System.out.println("All tests passed");
} else {
System.out.println("At least one test failed");
}
}
public static String translateScore (int score) {
return "";
}
【问题讨论】:
-
你将如何“获得”分数?会在控制台中作为起始参数传递吗?
-
并且不要将布尔值与
true进行比较;它已经是true或false。 -
Integer.toString 确实存在...以及 int + "";
-
为什么要翻译乐谱?似乎一开始就放弃翻译过程会更有效率。如果您需要翻译分数,我会推荐一组分配正确分数的 if 语句?或者,也许我误解了你想要做什么。你能说得清楚一点吗?