GuessGameTest.java 692 B

12345678910111213141516171819202122232425262728
  1. package homework.p08_guessgame;
  2. import java.util.Scanner;
  3. /**
  4. * @author WanJl
  5. * @version 1.0
  6. * @title GuessGameTest
  7. * @description
  8. * @create 2026/7/22
  9. */
  10. public class GuessGameTest {
  11. public static void main(String[] args) {
  12. GuessGame gg=new GuessGame(100);
  13. Scanner sc=new Scanner(System.in);
  14. while (true){
  15. System.out.print("请输入你猜的数字:");
  16. int num = sc.nextInt();
  17. String guess = gg.guess(num);
  18. System.out.println(guess);
  19. if (guess=="猜对了"){
  20. break;
  21. }
  22. }
  23. System.out.println("恭喜你!一共猜了 "+gg.getAttempts()+" 次");
  24. }
  25. }