编程语言
首页 > 编程语言> > 30道四则运算java

30道四则运算java

作者:互联网

package test4;

import java.util.Scanner;
import java.util.Random;
public class Test4 {
public static void dayin(int n6)
{Random r = new Random();
int i3= r.nextInt(10);
if(i3%4==0)
{
System.out.print("+");
}
if(i3%4==1)
{
System.out.print("-");
}
if(i3%4==2)
{
System.out.print("*");
}
if(i3%4==3)
{
System.out.print("/");
}


}
public static void dayin2(int n6)
{Random r = new Random();
int i3= r.nextInt(10);
if(i3%2==0)
{
System.out.print("+");
}
if(i3%2==1)
{
System.out.print("-");
}
}
public static void main(String[] args)
{Random r = new Random();
Scanner sc=new Scanner(System.in);
System.out.println("请输入操作数");
int n1=sc.nextInt();
System.out.println("请输入所要打印题目数量:");
int n2=sc.nextInt();
System.out.println("请输入所需打印方式:(每行几个)");
int n3=sc.nextInt();
System.out.println("请输入数字最大值:");
int n4=sc.nextInt();
System.out.println("是否有乘除 1:有 2:无");
int n5=sc.nextInt();
System.out.println("是否有括号 1:有 2:无");
int n6=sc.nextInt();
if(n5==1)
{int k=0;
for(int i=0;i<n2;i++)
{int first=r.nextInt(n4);
System.out.print( first);
int r1=r.nextInt(n1-2)+0;
int i1=r1+1;
int r2=r.nextInt(n1-1-i1)+i1+1;
//System.out.println(r1);
//System.out.println(r2);
for(int j=0;j<n1;j++)
{ if(n6==1)
{if(j==r2)
{
System.out.print(")");
}
}
dayin(n6);
if(n6==1)
{ if(j==r1)
{
System.out.print("(");
}
}
int i2 =r.nextInt(n4);
System.out.print(i2);
}

System.out.print("= ");

k++;
if(k%n3==0)
{
System.out.println();
}
}
}
if(n5==2)
{
int k=0;
for(int i=0;i<n2;i++)
{int first=r.nextInt(n4);
System.out.print( first);
int r1=r.nextInt(n1-2)+0;
int i1=r1+1;
int r2=r.nextInt(n1-1-i1)+i1+1;
//System.out.println(r1);
//System.out.println(r2);
for(int j=0;j<n1;j++)
{ if(n6==1)
{if(j==r2)
{
System.out.print(")");
}
}
dayin2(n6);
if(n6==1)
{ if(j==r1)
{
System.out.print("(");
}
}
int i2 =r.nextInt(n4);
System.out.print(i2);
}

System.out.print("= ");

k++;
if(k%n3==0)
{
System.out.println();
}
}
}
}
}

标签:30,java,int,四则运算,System,nextInt,print,println,out
来源: https://www.cnblogs.com/JIANGzihao0222/p/16687037.html