import java.util.Scanner;
import java.util.Random;
public class Coin_Head_Tail {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
Random generation=new Random();
int coin=generation.nextInt(2);
System.out.println("Welcome to the coin guess game.");
System.out.println("What is your guess? 0 for Head or 1 for Tail: ");
String ch= input.nextLine();
if(coin==0 && ch.equalsIgnoreCase("0"))
System.out.println("Congratulation, it is head");
else if(coin==1 && ch.equalsIgnoreCase("1"))
System.out.println("Congratulation, it is tail");
else
System.out.println("Sorry, try again");
}
}
I was wondering if there is another way around to solve the problem instead of using:
String ch= input.nextLine(); and ch.equalsIgnoreCase