TestBC07.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import java.util.Scanner;
  2. /**
  3. * ClassName: TestSwitch01
  4. * Package: PACKAGE_NAME
  5. * Description:
  6. *
  7. * @Author 爱扣钉-陈晨
  8. * @Create 2023/9/17 10:23
  9. * @Version 1.0
  10. */
  11. public class TestBC07 {
  12. /*
  13. break和continue
  14. */
  15. public static void main(String[] args) {
  16. for (int i = 0; i < 5; i++) {
  17. if (i == 3){
  18. continue;
  19. }
  20. System.out.println(i);
  21. }
  22. System.out.println("------------------");
  23. //猜数字案例 修改
  24. Scanner scanner = new Scanner(System.in);
  25. //随机数
  26. int number = (int) (Math.random() * 100);
  27. int num = 0;
  28. while ( true ){
  29. System.out.println("请输入猜测数字");
  30. num = scanner.nextInt();
  31. if (num > number ){
  32. System.out.println("输入的数字大了");
  33. }
  34. if (num < number ){
  35. System.out.println("输入的数字小了");
  36. }
  37. //break
  38. if (num == number){
  39. break;
  40. }
  41. }
  42. System.out.println("猜对了:"+num);
  43. }
  44. }