我正在尝试在 Java 中进行简单的抛硬币模拟,并且在玩过初始化等之后,我无法让字符串端初始化被抛掷模拟覆盖。
import java.util.*;
public class Coin {
public static void main(String [] args)
{
int randomNum = -1;
String side = "";
toss();
sideUp(randomNum);
getSideUp(side);
}
public static int toss()
{
Random rn = new Random();
int range = 2;
int randomNum = rn.nextInt(range);
return randomNum;
}
public static String sideUp(int randomNum)
{
String side;
if (randomNum == 0)
side = "heads";
else
side = "tails";
return side;
}
public static void getSideUp(String side)
{
System.out.println("The result is " + side + ".");
}
}