30道四则运算java

2022/9/13 14:17:56

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程