繁体   English   中英

我无法打印出 0。有人可以告诉我为什么吗?

[英]I can´t print out 0 . Can someone tell me why?

我无法打印出 0。有人可以告诉我为什么吗?

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
        System.out.print("Number: ");
        int number = read.nextInt();
        //your code goes here
        while (number >= 0) {
            if(number % 3 == 0) {
                number--;
                continue;
            }
            System.out.println(number);
            number--;
        }
    }
}

你继续通过0并且永远不会 output 它:

if(number % 3 == 0) {
   number--;
   continue;
}

0 % 3 == 0 // TRUE

您需要使用当前的逻辑对0案例进行特殊处理。 我会把它留给你来弄清楚那部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM