題目:
輸入想要開出幾個樂透數字
隨機產生出來,
如果輸入的部是數字,
或是大於48且小於6,
則被設定為6球
程式碼:
import java.lang.*;
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");
}
顯示結果: