軟體工程個人作業01

來源:互聯網
上載者:User

標籤:

設計思想:   整數運算  使用random()函數隨機產生兩個0到100的整數,用0到3數字代表加減乘除運算子,用random()隨機產生代表運算子的數字,如果是除法,還需考慮第二個數是否為0,如果是則重新進行一次隨機數產生,迴圈減一,最後輸出。

          真分數運算  使用random()函數隨機產生四個0到100的整數,用0到3數字代表加減乘除運算子,用random()隨機產生代表運算子的數字,需考慮第二個數和第四個數是否為0以及第一個數是否大於第二個數,第三個數是否大於第四個數,如果是則重新進行一次隨機數產生,迴圈減一,最後輸出。

來源程式代碼:

     import java.util.Scanner;

public class A{

   public static void main(String []args){

    int a,b,c,n=0;

    Scanner reader=new Scanner(System.in);

    System.out.print("整數運算請選 1,真分數運算請選  2:");

    n=reader.nextInt();

    if(n==1)

   {

    for(int i=1;i<=30;i++)

    {

       a=(int)(Math.random()*100+0);

       b=(int)(Math.random()*100+0);

       c=(int)(Math.random()*4+0);

      

       switch(c)

       {case 0:

          System.out.print(a+"+"+b+"="+"\t");

          break;

       case 1:

          System.out.print(a+"-"+b+"="+"\t");

          break;

       case 2:

          System.out.print(a+"*"+b+"="+"\t");

          break;

       case 3:

          if(b==0)

          {i--;break;}

          else

          System.out.print(a+"/"+b+"="+"\t");

            break;

         }

      

      if(i%5==0)

    {System.out.print("\n");}

     }

   }

    if(n==2)

   {

    int d,e,f,g,h;

    for(int i=1;i<=30;i++)

    {

       d=(int)(Math.random()*100+0);

       e=(int)(Math.random()*100+0);

       f=(int)(Math.random()*100+0);

       g=(int)(Math.random()*100+0);

       h=(int)(Math.random()*4+0);

       switch(h)

       {

       case 0:

           if(e==0||h==0||d>e||f>g)  

               {i--;break;}

           else

          System.out.println("("+d+"/"+e+")"+"+"+"("+f+"/"+g+")"+"="+"\t\t");

          break;

       case 1:

           if(e==0||h==0||d>e||f>g)  

               {i--;break;}

           else

          {System.out.println("("+d+"/"+e+")"+"-"+"("+f+"/"+g+")"+"="+"\t\t");

          break;}

       case 2:

           if(e==0||h==0||d>e||f>g)  

               {i--;break;}

           else

          {System.out.println("("+d+"/"+e+")"+"*"+"("+f+"/"+g+")"+"="+"\t\t");

          break;}

       case 3:

           if(e==0||h==0||d>e||f>g)  

               {i--;break;}

           else

           { System.out.println("("+d+"/"+e+")"+"/"+"("+f+"/"+g+")"+"="+"\t\t");

            break;}

         }

     }

   }

  }

}

運行結果:

 

軟體工程個人作業01

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.