如何使整数输入出现在提示用户输入的消息之后而不是之前?

时间:2018-12-08 22:53:49

标签: java while-loop java.util.scanner

我正在创建一个程序,在该程序中,反复要求用户输入输入,直到扫描仪读取0。由于某些奇怪的原因,每当我输入整数时,它就会在下一条消息要求输入之前出现。非常感谢。

    Scanner input = new Scanner(System.in);
    System.out.println("Enter an integer, the input ends if it is 0: ");

    int number;
    int posCount = 0;
    int negCount = 0;
    int total = 0;

    while((number = input.nextInt()) != 0) {
        System.out.println("Enter an integer, the input ends if it is 0:");
        if(number < 0) {

            negCount++; 

        }
        if(number > 0) {
            posCount++;

        }


        total += number;    
    }


    System.out.println("The number of negatives is " + negCount);
    System.out.println("The number of positives is " + posCount);
    System.out.println("The total is " + total);

1 个答案:

答案 0 :(得分:0)

请使用close all; clear all; clc; syms t real; syms thetak real; syms sik real; syms tbar real; syms sjk real; expr = exp(-thetak*((t-sik)^2 + (t-sjk)^2)); Bijk_raw = int(expr,t,0,1); Bijk = simplify(collect(expand(Bijk_raw))); fprintf('Bijk is as follows...\n'); pretty(Bijk); 的{​​{1}} isadad。

System.out.print()