|
PlayQuiz.java
import java.util.Scanner; class PlayQuiz { public static void main(String[] arg) { Scanner sc = new Scanner(System.in); String answer = "James Gosling"; System.out.println("Q. Who is the Inventor of Java? (You have 3 chances to answer correctly)");
for (int i = 0; i < 3; i++) {
String guess = sc.nextLine(); if (guess.equalsIgnoreCase(answer)) { System.out.println("GOOD!");
System.exit(0);
else if (i<2) System.out.println("No! Try again!"); } System.out.println("The correct answer is "+answer); } } |
|
See also
Ask It in The Java Forum Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|