Wang233333333 2020-07-27 18:38 采纳率: 100%
浏览 221
已采纳

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

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

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("你没机会了,游戏结束");
    }
}

    }
}

  • 写回答

3条回答 默认 最新

  • threenewbee 2020-07-27 19:50
    关注
    while(a<0)
    ->
    while(a>0)
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?