2018年11月4日 星期日

[Java]_ch6.2_大樂透



[Java]_ch6.2_大樂透

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Arrays;

public class A6_1

{

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

{

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader buf=new BufferedReader(isr);

System.out.print("請輸入隨機組數: ");

String s=buf.readLine();

int n=Integer.parseInt(s);

int A[]=new int[6];

for(int i=1;i<=n;i++) {

System.out.print("第"+i+"組:\t");

A[0]=(int)(Math.random()*49+1);

do {

A[1]=(int)(Math.random()*49+1);

}while(A[1]==A[0]);

do {

A[2]=(int)(Math.random()*49+1);

}while(A[2]==A[1] || A[2]==A[0]);

do {

A[3]=(int)(Math.random()*49+1);

}while(A[3]==A[2] || A[3]==A[1] || A[3]==A[0]);

do {

A[4]=(int)(Math.random()*49+1);

}while(A[4]==A[3] || A[4]==A[2] || A[4]==A[1] || A[4]==A[0]);

do {

A[5]=(int)(Math.random()*49+1);

}while(A[5]==A[4] || A[5]==A[3] || A[5]==A[2] || A[5]==A[1] || A[5]==A[0]);



for(int j=0;j<A.length;j++) {

System.out.print(A[j]+"\t");

}

System.out.print("\n排序後:\t");

Arrays.sort(A);

for(int j=0;j<A.length;j++) {

System.out.print(A[j]+"\t");

}

System.out.println();

}

}



}


沒有留言:

張貼留言

Ether.fi Cash Card 一張所有人必備的加密貨幣信用卡   [Ether.fi Cash Card] : https://www.ether.fi/app/cash/sign-up?ref_code=d27f8523 ------國際交易所------ [Bitg...