1、输入与输出
import java.util.*;
class InputTest{
public static void main(String args[]){
Scanner reader=new Scanner(System.in);
int n;
while(!reader.hasNextInt()){
reader.nextLine();
System.out.println("输入格式错误,请重新输入:");
}
n=reader.nextInt();
System.out.println("n="+n);
}
}
2、除法运算
import java.util.*;
class Division{
public static void main(String args[]){
Scanner reader=new Scanner(System.in);
int a,b=0;
double q;
System.out.println("请输入被除数:");
while(!reader.hasNextInt()){
reader.nextLine();
System.out.println("输入格式错误,请重新输入:");
}
a=reader.nextInt();
System.out.println("请输入除数:");
while(!reader.hasNextInt()){
reader.nextLine();
System.out.println("输入格式错误,请重新输入:");
}
b=reader