四则运算
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了四则运算相关的知识,希望对你有一定的参考价值。
public class sizeyunsuan { public static void main(String[] args) { Random random = new Random(); for (int j = 1; j <= 300; j++) { int algorithm = random.nextInt(4); int num1 = random.nextInt(100); int num2 = random.nextInt(100);
switch (algorithm) { case 0:
System.out.println("第" + j + "个:");
System.out.println(num1 + "*" + num2 + "=" ); break; case 1:
System.out.println("第" + j + "个:");
System.out.println(num1 + "+" + num2 + "=" ); break; case 2:
System.out.println("第" + j + "个:");
System.out.println(num1 + "-" + num2 + "=" ); break; case 3:
if (num2 == 0) {
j--; break; } else {
System.out.println("第" + j + "个:");
System.out.println(num1 + "/" + num2 + "=");
} break; default: break; } } }
}
以上是关于四则运算的主要内容,如果未能解决你的问题,请参考以下文章