呵呵 正巧我今天下午也做了一个类似的程序 这个是为了一个小游戏做的TEST 请高手指教
import java.util.Random;
import java.util.*;
public class Game
{
public static void main(String[] args)
{
{
int a, b = 0;
Scanner input = new Scanner(System.in);
System.out.println("Please enter the scope of the coins: ");
a=input.nextInt();
//
for(int i=0; i<1; ++i)
b = new Random().nextInt(a)+30;
System.out.println("\nThe number of coins is " + b);
}
Scanner input = new Scanner(System.in);
System.out.println("\nPlease choose the side of the coin:(0 or 1) ");
int Num = input.nextInt();
System.out.println("\nThe side you chose is " + Num);
int RandomNum = new Random().nextInt(2);
System.out.print("\nThe side of coin is " + RandomNum);
if (Num == RandomNum)
{
System.out.print("\n\nCongratulations! Please take the coins:");
}
else
{
System.out.print("\n\nSorry, Wrong side, Please wait...");
}
}
}