简单的抛硬币问题?不知错在哪了?
import java.util.*;
public class Test6 {
/**
* @param args
*/
public static void main(String[] args) {
int rand;
long a=0,b=0;
Random rander=new Random();
Scanner in=new Scanner(System.in);
if(in.hasNextLong())System.out.println("please input again!");
long i=in.nextLong();
while(i>0){
rand=rander.nextInt()+1;
if(rand>25) b++;
else a++;
i--;
}
try{
in.close();
System.out.println("正面次数为:"+a+"\n"+"反面次数为:"+b);
}catch (Exception e) {
System.out.println("Sorry!");
}
}
}