- import java.util.Scanner;
- class Test3 {
-
- public static int shuZi9(int a) { //判断一个数每一位是否包含9
- while(true) {
-
- int b = a%10;
- a /=10;
-
- if (b==9) {
-
- int c = 1;
- return c; //return直接结束了方法,也就跳出了死循环
-
- }
-
- if (a==0) {
- int c =0;
- return c;
- }
-
- }
- }
-
- public static void main(String[] args) {
-
- Scanner sc = new Scanner(System.in);
-
- System.out.print("请输入要检测的数据:");
-
- int a = sc.nextInt();
- for (int x = 1;x<=a ;x++ ) {
-
- int b = shuZi9(x);
- if(b==1) {
-
- continue;
- }
-
- System.out.println(x);
- }
-
- }
- }
复制代码 试着改了一下,随意键入一个数字,判断每一位是否有9,有则跳出一次。
|