import java.util.*; public class CoinToss { public static void main(String[] args) { Random g = new Random(); // g for "generator" Scanner in = new Scanner(System.in); int x = g.nextInt(2) + 1; // flip a coin, 1 = heads, 2 = tails System.out.print("Call it: 1 for heads, 2 for tails: "); int call = in.nextInt(); // get user's input as an integer String output = "The coin is a "; // we will start with this String for output and add to it with the following logic if(x==1) output = output + "heads\n"; // based on the random number, add "heads" or "tails" to the output String else output = output + "tails\n"; if(call==1) output = output + "You guessed heads\n"; // based on user's input, add what the user else output = output + "You guessed tails\n"; // called it if(x==call) output = output + "You guessed right!!!"; // finally add whether the user is right or wrong else output = output + "You guessed wrong."; System.out.println(output); } }