四则运算问题 Java
作者:互联网
1 package helloword1; 2 3 import java.util.Random; 4 import java.util.Scanner; 5 public class Test { 6 public static void main(String[] args) { 7 zuoYe(); 8 } 9 10 public static void shuZi() { 11 Random random=new Random(); 12 int a=random.nextInt(100)+1; 13 System.out.print(a); 14 } 15 16 public static void fuHao(int p) { 17 Random random=new Random(); 18 if(p==1){ 19 int a=random.nextInt(4)+1; 20 if(a==1) System.out.print("+"); 21 if(a==2) System.out.print("-"); 22 if(a==3) System.out.print("*"); 23 if(a==4) System.out.print("/"); 24 } 25 else { 26 int a=random.nextInt(2)+1; 27 if(a==1) System.out.print("+"); 28 if(a==2) System.out.print("-"); 29 } 30 } 31 32 33 public static void zuoYe() { 34 Scanner sc=new Scanner(System.in); 35 Random random=new Random(); 36 System.out.println("请输入操作数:"); 37 int b=sc.nextInt(); 38 System.out.println("请输入题目个数:"); 39 int a=sc.nextInt(); 40 System.out.println("请输入每行的题数:"); 41 int h=sc.nextInt(); 42 System.out.println("请输入题目中是否有乘除法:1是 2否"); 43 int p=sc.nextInt(); 44 System.out.println("请输入题目中是否有括号:1是 2否"); 45 int q=sc.nextInt(); 46 sc.close(); 47 48 for( int i=1;i<=a;i++){ 49 if(q==1) { 50 int c=random.nextInt(5); 51 if(c!=0) { 52 shuZi(); 53 for (int j = 0; j < b - 1; j++) { 54 if (j < b - 2) { 55 int d=random.nextInt(5); 56 if (d == 1) { 57 fuHao(p); 58 System.out.print("("); 59 shuZi(); 60 fuHao(p); 61 shuZi(); 62 System.out.print(")"); 63 j++; 64 } 65 else { 66 fuHao(p); 67 shuZi(); 68 } 69 } 70 else { 71 fuHao(p); 72 shuZi(); 73 } 74 } 75 } 76 else{ 77 System.out.print("("); 78 shuZi(); 79 fuHao(p); 80 shuZi(); 81 System.out.print(")"); 82 for (int j = 1; j < b - 1; j++) { 83 if (j < b - 2) { 84 int d=random.nextInt(5); 85 if (d == 1) { 86 fuHao(p); 87 System.out.print("("); 88 shuZi(); 89 fuHao(p); 90 shuZi(); 91 System.out.print(")"); 92 j++; 93 } 94 else { 95 fuHao(p); 96 shuZi(); 97 } 98 } 99 else { 100 fuHao(p); 101 shuZi(); 102 } 103 104 105 } 106 } 107 } 108 109 else { 110 for(int k=1;k<=b;k++) 111 { 112 shuZi(); 113 if(k==b) {} 114 else fuHao(p); 115 } 116 } 117 118 System.out.print("=\t\t"); 119 if(i%h==0) 120 { 121 System.out.println(); 122 } 123 } 124 } 125 126 127 }
标签:Random,Java,int,四则运算,System,问题,nextInt,print,out 来源: https://www.cnblogs.com/yangjialong/p/16686495.html