标签:next text 运算 exti case 作业 compute ack color
1 package demo; 2 3 import java.text.DecimalFormat; 4 import java.util.Random; 5 6 public class Demo { 7 8 public static void main(String[] args) { 9 maths(); 10 } 11 12 public static void maths() { 13 Random number = new Random(); 14 for (int x = 1; x <= 300; x++) { 15 int compute = number.nextInt(4); 16 int a = number.nextInt(100); 17 int b = number.nextInt(100); 18 switch (compute) { 19 case 0: 20 System.out.println("第" + x + "条:"); 21 System.out.println(a + "+" + b + "=" + (a + b)); 22 break; 23 case 1: 24 System.out.println("第" + x + "条:"); 25 System.out.println(a + "-" + b + "=" + (a - b)); 26 break; 27 case 2: 28 System.out.println("第" + x + "条:"); 29 System.out.println(a + "×" + b + "=" + (a * b)); 30 break; 31 case 3: 32 if (b == 0) { 33 x--; 34 break; 35 } else { 36 if (a % b == 0) { 37 System.out.println("第" + x + "条:"); 38 System.out.println(a + "÷" + b + "=" + (a / b)); 39 } else { 40 System.out.println("第" + x + "个:"); 41 double c = (double) a / b; 42 String y = new DecimalFormat("0.00").format(c); 43 System.out.println(a + "÷" + b + "=" + y); 44 } 45 } 46 break; 47 default: 48 break; 49 } 50 } 51 } 52 }
标签:next text 运算 exti case 作业 compute ack color
原文地址:http://www.cnblogs.com/Wwwyyf/p/6533610.html