为什么我的代码没有报错,可是运行的时候没有办法打出字来。

为什么我的代码没有报错,可是运行的时候没有办法打出字来

package one;

import java.util.Scanner;

public class one {
    public static void main(String[] args) {
        System.out.print("我叫王宇昊,今天开始我要努力学习JAVA开发了,我现在是大学生,你可以猜一猜我的年龄:");
        Scanner input = new Scanner(System.in);
        int a = 4;
while(a<0){
    a--;
    int age = input.nextInt();
    if (age < 20) {
        System.out.println("猜小了,你还有" + a + "次机会");
    } else if (age > 20) {
        System.out.println("猜大了,你还有" + a + "次机会");
    } else {
        System.out.println("猜对了,游戏结束");
        break;
    }
    if (a == 0) {
        System.out.println("你没机会了,游戏结束");
    }
}

    }
}

while(a<0)
->
while(a>0)

问题解决的话,请点下采纳。

因为你a 初始值为4,进不了你下面while循环。

while 判断为true才能进入,也就是改为while(a > 0)即可