简单的四则运算

public class Test {
public static void res(){
System.out.println("1.显示结果\t2.直接开始下一题");
}
public static void main (String[] arge){
System.out.println("*****请选择要随机生成的算法*****");
System.out.println("\t1,加法\t2,减法\t3,乘法\t4,除法");
System.out.println("**********");
Scanner sc=new Scanner(System.in);
int s = sc.nextInt();
double result=0;
Random r = new Random();
int a = r.nextInt(100);
int b =r.nextInt(100);
switch(s){
case 1:System.out.println("-----|"+a+"+"+b+"=?|-----");result =a+b;res();break;
case 2:System.out.println("-----|"+a+"-"+b+"=?|-----");result =a-b;res();break;
case 3:System.out.println("-----|"+a+"*"+b+"=?|-----");result =a*b;res();break;
case 4:System.out.println("-----|"+a+"/"+b+"=?|-----");{float c=a;float d=b;result=c/d;}res();break;
default:System.out.println("输入有误,重新开始");main(null);break;
}
Scanner select =new Scanner(System.in);
int se =select.nextInt();
switch (se){
case 1:System.out.println("本题的结果:"+result);main(null);break;
case 2:main(null);break;
default:System.out.println("输入有误,重新开始");main(null);
}
}
}

 


posted @ 2017-03-09 10:39  wangyongdong19  阅读(95)  评论(0编辑  收藏  举报