package j; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner (System.in); System.out.println("題目的數量"); int number=in.nextInt(); System.out.println("數值範圍 10 空格 200 ");//先考慮整數的 int up,down; down=in.nextInt(); up=in.nextInt(); System.out.println("列印時每行的間隔"); int between; between=in.nextInt(); System.out.println("是否有乘除法Y/N"); String jud1,jud2,jud3; jud1=in.next(); System.out.println("是否支援小數Y/N"); jud2=in.next(); System.out.println("加減有無負數Y/N"); jud3=in.next(); /*char jud4; System.out.println("是否有括號Y/N"); jud4=in.nextLine().charAt(0); System.out.println(number+""+down+"-"+up+""+between+""+jud1+""+jud2+""+jud3+""+jud4); */ do{ int flag; int shuzi; int b; int c=(int)Math.random()*4+1; float shuzi2; int signal=0; String Temp=new String("Y"); if(c<2)flag=2; else if (c==3)flag=3; else flag=4; if(jud2.equalsIgnoreCase(Temp))//是否有小數點 { if(jud3.equalsIgnoreCase(Temp))//是否有負數 signal=(int) (Math.random()*2); shuzi2=(float)(Math.random()*(up-down))+down; shuzi2=(int)(shuzi2*1000); shuzi2=shuzi2/1000; if(signal<1) System.out.print(shuzi2); else System.out.print("(-"+shuzi2+")"); } else{ if(jud3.equalsIgnoreCase(Temp)) signal=(int) (Math.random()*2); shuzi=(int)(Math.random()*(up-down)+down); if(signal<1) System.out.print(shuzi); else System.out.print("(-"+shuzi+")"); } //以上是第一個數 do{ if(jud1.equalsIgnoreCase(Temp))//是否有乘除 b=(int)(Math.random()*4+1); else b=(int)(Math.random()*2+1); switch(b){ case 1://加 if(jud2.equalsIgnoreCase(Temp))//是否小數點 { shuzi2=(float)(Math.random()*(up-down))+down; shuzi2=(int)(shuzi2*1000); shuzi2=shuzi2/1000; System.out.print("+"+shuzi2); } else{ shuzi=(int)(Math.random()*(up-down)+down); System.out.print("+"+shuzi); } break; case 2://減 if(jud2.equalsIgnoreCase(Temp)) { shuzi2=(float)(Math.random()*(up-down))+down; shuzi2=(int)(shuzi2*1000); shuzi2=shuzi2/1000; System.out.print("-"+shuzi2); } else{ shuzi=(int)(Math.random()*(up-down)+down); System.out.print("-"+shuzi); } break; case 3://乘 if(jud2.equalsIgnoreCase(Temp)) { shuzi2=(float)(Math.random()*(up-down))+down; shuzi2=(int)(shuzi2*1000); shuzi2=shuzi2/1000; System.out.print("*"+shuzi2); } else{ shuzi=(int)(Math.random()*(up-down)+down); System.out.print("*"+shuzi); } break; case 4://除 if(jud2.equalsIgnoreCase(Temp)) { shuzi2=(float)(Math.random()*(up-down))+down; shuzi2=(int)(shuzi2*1000); shuzi2=shuzi2/1000; System.out.print("/"+shuzi2); } else{ shuzi=(int)(Math.random()*(up-down)+down); System.out.print("/"+shuzi); } break; } flag--; }while(flag>0); System.out.print("="); number--; for(int k=1;k<=between;k++) System.out.println(); }while(number>0); } }