- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Random;
- public class test12 {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // BufferedReader继承自Readed类
- char[] ch = { '+', '-', '*', '/' };
-
- System.out.print("please input:");
- String str1 = br.readLine();
- int num1 = Integer.parseInt(str1);
-
- System.out.print("please input:");
- String str2 = br.readLine();
- int num2 = Integer.parseInt(str2);
- // System.out.println(ch[0]);
- Random r = new Random();
- int i = r.nextInt(4);
- switch (i) {
- case 0:
- System.out.println(ch[i] + ":" + (num1 + num2));
- break;
- case 1:
- System.out.println(ch[i] + ":" + (num1 - num2));
- break;
- case 2:
- System.out.println(ch[i] + ":" + (num1 * num2));
- break;
- case 3:
- System.out.println(ch[i] + ":" + (num1 / num2));
- break;
- }
- }
- }
复制代码 |