随机选取幸运观众

import java.util.*;
public class LuckNumber {
public static void main(String[] args) {
//方式一
int luckNumber =(int)(Math.random()*10+1);
System.out.println("本期的幸运号码是:" + luckNumber);
int choosen=(int)(Math.random()*10+1);
System.out.println("您抽到的号码为:" + choosen);
if(choosen==luckNumber){
System.out.println("恭喜您成为本期的幸运观众!!!");
}else{
System.out.println("很遗憾,幸运大奖和您擦肩而过!!!");

}

//方式二

  Random random=new Random();
int luckNumber=random.nextInt(10)+1;
System.out.println("本期的幸运号码是:" + luckNumber);
int choosen=random.nextInt(10)+1;
System.out.println("您抽取的号码是:" + choosen);
if(luckNumber==choosen){
System.out.println(luckNumber);
System.out.println("恭喜您成为本期的幸运观众!!!");

}else{
System.out.println("很遗憾,幸运大奖和您擦肩而过!!!");


}
 


}
}




你可能感兴趣的:(随机数,java,Random)