close

題目:

輸入想要開出幾個樂透數字
隨機產生出來,
如果輸入的部是數字,
或是大於48且小於6,
則被設定為6球


程式碼:


import java.lang.*;

import java.io.*;

public class Lotto 
{

public static void main(String args[]) throws IOException 

{

//Console console=System.console();

BufferedReader console=new BufferedReader(new InputStreamReader(System.in));

System.out.print("請輸入陣列大小\n");

int lottoSize=0;

try

{

lottoSize=Integer.parseInt(console.readLine());

if((lottoSize>48)||(lottoSize<6))

throw new CmyException1();

}

catch(NumberFormatException e)

{

System.out.println("set six");

lottoSize=6;

}

catch(CmyException1 e)

{

e.showMessage();

lottoSize=e.changeSize();

}

finally

{

System.out.println("the lotto numer is"+lottoSize);

}

   int lottoAry[]=new int[lottoSize];

   

   for(int j=0;j<lottoSize;j++)

   {

    lottoAry[j]=(int) (Math.random()*100);

   }

   for(int i:lottoAry)

   {

    System.out.println(i);

   }  

System.out.println("lotto over");

}

}

顯示結果:


請輸入陣列大小6
the lotto numer is6
99
35
73
39
32
96
lotto over
arrow
arrow
    文章標籤
    Java
    全站熱搜
    創作者介紹
    創作者 布拉怡 的頭像
    布拉怡

    nini的部落格

    布拉怡 發表在 痞客邦 留言(0) 人氣()