首页 > 代码库 > 作业:小学300道四则运算题
作业:小学300道四则运算题
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 }
作业:小学300道四则运算题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。