Design and implement an application that reads a string from the user and prints it one character per line.


EX: 使用者輸入: abcde,








Design and implement an application that plays the Hi-Lo guessing game with numbers. The program should pick a random number between 1 and 100(inclusive), then repeatedly prompt the user to guess the number. On each guess, report to the user that he or she is correct or that the guess is high or low. Continue accepting guesses until the user guesses correctly or choose to quit. Use a sentinel value to determine whether the user wants to quit. Count the number of guesses and report that value when the user guesses correctly. At the end of each game(by quitting or a correct guess), prompt to determine whether the user wants to play again. Continue playing games until the user chooses to stop.



讓使用者可重複做猜數字的動作直到猜對為止或是使用者選擇結束(設定一個結束的指令 EX:使用者輸入Q即為結束)

每當使用者猜對數字或是選擇結束後 詢問使用者是否要繼續玩

是的話 重新讓使用者玩遊戲直到使用者選擇不玩為止

1 Answer

  • 1 decade ago
    Favorite Answer


    import java.util.*;public class Y9611 { public static void main(String[] args) { Q1(); Q2(); } public static void Q1() { Scanner scan = new Scanner(; System.out.print("Please input a string: "); String s =; for (int i = 0; i < s.length(); i++) { System.out.println(s.charAt(i)); } } public static void Q2() { Scanner scan = new Scanner(; while (true) { final int x = (int)(Math.random() * 100 + 1); System.out.println("A random number (1~100) is generated."); while (true) { System.out.print("Please take a guess ('Q' to stop): "); String s =; if (s.equalsIgnoreCase("Q")) break; int a = Integer.parseInt(s); if (a == x) { System.out.println(a + " is the correct answer!"); break; } else if (a > x) { System.out.println(a + " is too high."); } else { System.out.println(a + " is too low."); } } System.out.print("Continue (y/n)? "); String s =; if (s.equalsIgnoreCase("n")) break; } }}

Still have questions? Get your answers by asking now.