其他分享
首页 > 其他分享> > 二柱子

二柱子

作者:互联网

package kaoshi;

import java.util.Random;
import java.util.Scanner;

public class erzhuzigan {
public static void main(String[] args) {
zuoYe();
}

public static void shuZi() {
Random random=new Random();
int a=random.nextInt(100)+1;
System.out.print(a);
}

public static void fuHao() {
Random random=new Random();
int a=random.nextInt(4);
if(a==0){
System.out.print("+");
}
if(a==1){
System.out.print("-");
}
if(a==2){
System.out.print("*");
}
if(a==3){
System.out.print("/");
}
}

public static void zuoYe() {
Scanner sc=new Scanner(System.in);
Random random=new Random();
System.out.println("请输入操作数:");
int b=sc.nextInt();
System.out.println("请输入题目个数:");
int a=sc.nextInt();
for(int i=0;i<a;i++){
int c=random.nextInt(5);
if(c!=0) {
shuZi();
for (int j = 0; j < b - 1; j++) {
if (j < b - 2) {
int d=random.nextInt(5);
if (d == 1) {
fuHao();
System.out.print("(");
shuZi();
fuHao();
shuZi();
System.out.print(")");
j++;
}
else {
fuHao();
shuZi();
}
}
else {
fuHao();
shuZi();
}
}
}
else{
System.out.print("(");
shuZi();
fuHao();
shuZi();
System.out.print(")");
for (int j = 1; j < b - 1; j++) {
if (j < b - 2) {
int d=random.nextInt(5);
if (d == 1) {
fuHao();
System.out.print("(");
shuZi();
fuHao();
shuZi();
System.out.print(")");
j++;
}
else {
fuHao();
shuZi();
}
}
else {
fuHao();
shuZi();
}
}
}
System.out.println("=");
}
}
}
用了比较笨的方法,但是总体思路还算是比较清晰的,明天把二柱子和论文两个加上注释,读者们就更方便理解了。

标签:柱子,int,System,fuHao,shuZi,print,out
来源: https://www.cnblogs.com/zhiqi2625/p/15321925.html