I am trying to make a simple coin toss simulation in Java, and after playing around with initializations and such, I can't get the String side initialization to be overridden by the toss simulation.
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 + ".");
}
}