简体   繁体   English

结束循环后系统输出 println 不起作用

[英]System out println don't work after end loop

Hello guys (sorry bad english) I'm looking for answer on my own but I'm stuck and I don't know why it doesn't work :x (Please don't mock me, that's my first day on Java T_T )大家好(对不起,英语不好)我正在寻找自己的答案,但我被卡住了,我不知道为什么它不起作用:x(请不要嘲笑我,这是我在 Java 上的第一天 T_T )

I think that's obvious for you, but I have我认为这对你来说很明显,但我有

"It looks like your post is mostly code; please add some more details." “看起来您的帖子主要是代码;请添加更多详细信息。”

so : when I type 0 and enter, code supposed to stop running the loop and show last lines, but I get nothing on the console :x所以:当我输入 0 并输入时,代码应该停止运行循环并显示最后几行,但我在控制台上什么也没得到:x

Here's the code这是代码

package fr.eni.demo;

import java.util.Scanner;

public class Cheque
{

    static double nbCheques = 0;
    static double total = 0;
    static double moyenne = 0;
    static double inf200 = 0;
    static double totalInf200 = 0;
    static double egalSup200 = 0;
    static double totalEgalSup200 = 0;
    static double numeroPlusPetit = 0;
    static double plusPetit = 0;
    static double numeroPlusGrand = 0;
    static double plusGrand = 0;


public static void main(String[] args)
{
    Scanner scan = new Scanner(System.in);
    System.out.println("Entrez le montant du chèque. 0 pour quitter.");
    double input = scan.nextDouble();
    
    while (input != 0);
    {
        nbCheques++;
        total = total + input;
            if (input < 200)
            {
                inf200++;
                totalInf200 = totalInf200 + input;
                plusPetit = input;          
                
                while (input < plusPetit)
                    {
                        plusPetit = input;
                        numeroPlusPetit = nbCheques;
                    }
            }
            else 
            {
                egalSup200++;
                totalEgalSup200 = totalEgalSup200 + input;
                plusGrand = input;  
                
                while (input > plusGrand)
                {
                    plusGrand = input;
                    numeroPlusGrand = nbCheques;
                }
            }
    } 
    moyenne = total/moyenne;
    System.out.println("Nombre(s) de chèque(s) : " + nbCheques);
    System.out.println("Montant total : " + total);
    System.out.println("Moyenne totale : " + moyenne);
    System.out.println("Chèque(s) inférieur(s) à 200€ : " + inf200);
    System.out.println("Montant total des chèques < 200€ : " + totalInf200 +"€");
    System.out.println("Chèque(s) supérieur(s) ou = à 200€ : " + egalSup200);
    System.out.println("Montant total des chèques >= 200€ : " + totalEgalSup200 +"€");
    System.out.println("#Chèques plus petit : " + numeroPlusPetit);
    System.out.println("Plus petit montant : " + plusPetit +"€");
    System.out.println("#Chèques plus grand : " + numeroPlusGrand);
    System.out.println("Plus grand montant : " + plusGrand +"€");
    
}

}

I think you misunderstanding here.我想你在这里误解了。

double input = scan.nextDouble();

This line will only scan the console ONCE for the input, meaning you will only get two result from your program:此行只会扫描控制台一次以获取输入,这意味着您只会从程序中获得两个结果:

  • You enter 0 and the program prints all logs then exit.您输入 0 并且程序打印所有日志然后退出。
  • You enter a double differs 0 and the program keep running forever since the input value is not updated inside the loop.您输入一个 double 不同 0 并且程序将永远运行,因为输入值未在循环内更新。

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

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