A+B和C
提交代码一直提示答案错误,后来发现是因为输出的Case首字母未大写。用了两种方式都通过了。
方法一:让结果在回车后一起输出;
import java.util.Scanner;
public class Main2 {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int t;//输入的测试用例个数
int num=0;//输出的测试用例个数,即case处的值
long a,b,c;
t=in.nextInt();
boolean[] result=new boolean[t];
for(int i=0;i<t;i++)
result[i]=false;
while(num<t){
a=in.nextLong();
b=in.nextLong();
c=in.nextLong();
if((a+b)>c)
result[num]=true;
++num;
}
for(int i=0;i<result.length;i++){
if(result[i]==true){
System.out.println("Case #"+(i+1)+": "+"true");
}
else{
System.out.println("Case #"+(i+1)+": "+"false");
}
}
}}
方法二:键盘写入一行输出一行的结果;
import java.util.Scanner;
public class Main2 {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int t;
int num=0;
long a,b,c;
t=in.nextInt();
while(num++<t){
a=in.nextLong();
b=in.nextLong();
c=in.nextLong();
if((a+b)>c){
System.out.println("Case #"+num+": "+"true");
}
else{
System.out.println("Case #"+num+": "+"false");
}
}
}
}