そしてロトの妹成基の異常処置.


import java.util.*;
class InputNumException extends Exception
{
InputNumException()
{
super(「0枚以下は購入できません」);
}
}
class Lotto
{
private int[]number;
private int[] lotto;
private final int MAX=6;
private final int RANGE=45;
private Random random;
Lotto()
{
	number=new int[RANGE];
	lotto=new int[MAX];
	random=new Random();
	for(int i=0; i<number.length; i++)
	{
		number[i]=i+1;
	}
}
public void execute()
{
	shuffle();
	sortArr();
	printLotto();
}
public void shuffle()
{
	for(int i=0; i<number.length; i++)
	{
		for(int j=i+1; j<20; j++)
		{
			int temp=0;
			int k=random.nextInt(45);
			temp=number[i];
			number[i]=number[k];
			number[k]=temp;
		}
	}
}
public void sortArr()
{
	for(int i=0; i<lotto.length; i++)
	{
		lotto[i]=number[i];
	}
	for(int i=0; i<lotto.length-1; i++)
	{
		int temp=0;
		if(lotto[i]>lotto[i+1])
		{
			temp=lotto[i];
			lotto[i]=lotto[i+1];
			lotto[i+1]=temp;
		}
	}
}
public void printLotto()
{
	for(int i=0; i<lotto.length; i++)
		System.out.print(lotto[i]+ " ");
	System.out.println();
}
}
class LottoMain
{
public static void main(String[] args)
{
Lotto lotto=new Lotto();
try
{
int num=InputNum();
for(int i=0; i{
lotto.execute();
}
}
catch(InputNumException e)
{
e.printStackTrace();
}
}
public static int InputNum() throws InputNumException
{
Scanner sc=new Scanner(System.in);
System.out.println(「何枚買いますか?」
int num=sc.nextInt();
if(num<=0)
{
InputNumException nexcp=new InputNumException();
throw nexcp;
}
return num;
}
}