Scanner的用法:单行/多行的输入
特别注意:如果前面使用sc.nextInt()或者sc.nextLong()等这一类的获取数据,后面如果想使用sc.nextLine()获取数据必须使用换行。
比如,
// 输入如下,第一行的数字代表下面的行数
2
101 2 3
4B 12 13
下面这种写法是错误的,因为没使用换行。不管第一行的数据使用sc.nextInt()的方式是否获取完,下面想使用sc.nextLine()必须加换行。
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNextLine()){
int num=sc.nextInt();
for(int i=0;i<num;i++){
String str=sc.nextLine();
long sum=0;
String[] arr=str.split(" ");
for(int j=1;j<arr.length;j++){
long tem=Long.parseLong(arr[0],Integer.parseInt(arr[j]));
sum=(sum+tem%10)%10;
}
if(sum==0){
System.out.println(0);
}else{
if(sum%2==0){
System.out.println(0);
}else{
System.out.println(1);
}
}
}
}