简体   繁体   English

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

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

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--;
        }
    }
}

You continue passed the 0 and never output it:你继续通过0并且永远不会 output 它:

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

0 % 3 == 0 // TRUE

You will need to have special handling for the 0 case with the logic you have currently.您需要使用当前的逻辑对0案例进行特殊处理。 I will leave it for you to figure that part out.我会把它留给你来弄清楚那部分。

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

相关问题 有人可以告诉我为什么out.println不起作用吗? - Can someone please tell me why the out.println isn't working? 有人可以告诉我为什么我得到这个输出吗? - Can someone tell me why I get this output? 谁能告诉我为什么这个if语句总是给我假的? - can someone tell me why this if statement always give me false? 有人可以告诉我为什么这不能打印正确的分数吗? 它只是退出循环 - Can someone tell me why this is not printing the correct score; it just exits out of the loop 有人可以告诉我为什么我的获胜条件不起作用吗? - Can someone please tell me why my winning conditions aren't working? 有人可以告诉我为什么键绑定不起作用吗? - Can someone please tell me why the key-bindings don't work? 有人可以告诉我为什么我的listView不填充JSON数据吗 - Can someone tell me why my listView isn't populating with the JSON data 有人能告诉我为什么我的程序没有运行吗? - Can someone tell me why my program isnt running? 有人能告诉我为什么这种方法会进入无限循环吗? - Can someone tell me why this method is going into an infinite loop? 有人能解释一下为什么只有字符串 s4 的打印结果是 10bab 吗? - Can someone explain me why the print of only string s4 turns out to be 10bab?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM