Java 的Scanner sc.hasNext() ,下面的程序,奇数时读入String,偶数读入Int,下面的while无法退出
importjava.util.Scanner;publicclass临时{publicstaticvoidmain(String[]args){Scannersc=ne...
import java.util.Scanner;
public class 临时 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter(" |:");
int flag = 1;
while(sc.hasNext()){
if(flag % 2 != 0){
System.out.println(sc.next());
}
else{
System.out.println(sc.nextInt());
}
flag++;
}
System.out.println("ASDF");
sc.close();
}
} 展开
public class 临时 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter(" |:");
int flag = 1;
while(sc.hasNext()){
if(flag % 2 != 0){
System.out.println(sc.next());
}
else{
System.out.println(sc.nextInt());
}
flag++;
}
System.out.println("ASDF");
sc.close();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询