用java写随机出题

 1 import java.io.*;      //输入函数包
 2 public class hello{
 3     public static void main(String args[]){
 4         String s="";
 5         int sum1,sum2,sum3;
 6         sum1=(int)(Math.random()*100+1);
 7         sum2=(int)(Math.random()*100+1);
 8         sum3=(int)(Math.random()*100+1);
 9         System.out.println(sum1+"+"+sum2+"-"+sum3);
10         try
11         {
12             BufferedReader in=new BufferedReader(
13                                                 new InputStreamReader(System.in));
14             s=in.readLine();
15         }
16         catch(IOException e){}
17         int sum=Integer.parseInt(s);
18         if(sum==sum1+sum2-sum3)
19             System.out.println("yes");
20         else
21             System.out.println("NO");
22     }
23 }
posted @ 2016-11-22 16:50  Doublekai  阅读(1688)  评论(0编辑  收藏  举报