Java - Compare two string ignoring case

Description

Compare two string ignoring case

Demo

import java.util.Scanner;

public class QuizShow {

  public static void main(String args[]) {
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Which rodent first got to America by stowing away on ships?"
        + "\n Rats \t Squirrels \n Gerbils \t Beavers");
    String rodent = keyboard.nextLine();
    keyboard.close();/*from  w  ww  . java2  s .  co  m*/

    System.out.println("What is your answer?");
    System.out.println(rodent);

    String answer = "rats";

    if (rodent.equalsIgnoreCase(answer)) {
      System.out.println("Right");
    }
    else{
      System.out.println("Wrong");
    }
  }
}

Related Topic