Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

30道四则运算java

 Share


NedK7

Recommended Posts

 

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();
}
}
}
}
}

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...