JAVA的String output 和output +=是什么作用?
关注:248 答案:2 mip版
解决时间 2021-01-17 13:47
提问者我不想放过你
2021-01-16 17:55
import java.util.Scanner;
public class SubtractionQuizLoop
{
public static void main(String[] args)
{
// TODO Auto-generated method stud
final int NUMBER_OF_QUESTIONS = 5;
int correctCount = 0;
int count = 0;
long startTime = System.currentTimeMillis();
String output = " ";
Scanner input = new Scanner(System.in);
while (count < NUMBER_OF_QUESTIONS)
{
int number1 = (int)(Math.random() * 10);
int number2 = (int)(Math.random() * 10);
if(number1 < number2)
{
int temp = number1;
number1 = number2;
number2 = temp;
}
System.out.print("What is " + number1 + "-" + number2 + "?");
int answer = input.nextInt();
if(number1 - number2 == answer)
{
System.out.println("You are correct!");
correctCount++;
}
else
System.out.println("You answer is wrong.\n" + number1 + "-"
+ number2 + " should be " + (number1-number2));
count++;
output += "\n" + number1 + "-" + number2 + "=" + answer +
((number1 - number2 == answer)?"correct":"wrong");
}
long endTime = System.currentTimeMillis();
long testTime = endTime - startTime;
System.out.println("Correct count is" + correctCount +
"\nTest time is " + testTime/1000 +" seconds\n" + output);
}
}
最佳答案
二级知识专家纨绔ソ少年
2021-01-16 19:11
output +="……" 的意思就是是 output=output+“……”;连接字符串。
全部回答
1楼吃貨一枚
2021-01-16 20:08
不是固定用法,就是一个表达式。
比如 4 的平方是 16, 2 的平方是 4
我要举报
如以上问答内容为低俗/色情/暴力/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
→点此我要举报以上信息!←
推荐资讯
大家都在看