我已经接受了一个字符串数组的输入。.由于既有int字符串输入,因此我在每个int输入之后都使用newLine(),并且还尝试将newLine()放在字符串输入之后,但尚未打印字符串。这是怎么了?
提前感谢
class Bfaf{
public static void main(String[]args){
Scanner scan = new Scanner(System.in);
int n =scan.nextInt();
stra[] str = new stra[n];
for(int i =0 ; i< n ; i++){
scan.nextLine(); //As taken int input
String s = scan.nextLine();
//scan.next();
int t = scan.nextInt();
str[i] = new stra(s,t,i+1);
}
for(int i= 0; i< n ;i++){
System.out.println( str[i].str1 + " "+str[i].num);
}
}
}
class stra{
String str1;
int num ;
int id ;
stra(String str1 , int num , int id){
this.str1 = str1 ;
this.num = num ;
this.id = id ;
}
}
输入:2 凯尔20 艾哈迈德40
预计:凯尔20 艾哈迈德40
实际:20 40