简体   繁体   English

我在打印数字时遇到问题

[英]I am having trouble printing numbers

I am trying to do get user input with scanner for salesTotal variable and there is 2 if statements but it does not display my commision rate right.İt gives me 0 for every value that i write.我正在尝试使用扫描仪获取 salesTotal 变量的用户输入,并且有 2 个 if 语句,但它没有正确显示我的佣金率。对于我写的每个值,它都给我 0。

import java.util.Scanner;

public class Q2 {
    public static void main(String[] args) {

        double commisionRate = 0;
        double salesTotal;

        Scanner sc = new Scanner(System.in);

        salesTotal = sc.nextDouble();

    if(salesTotal <=10.000){
        commisionRate = (commisionRate*100)/2;
        System.out.println("the commision rate is : " +commisionRate);

    }
    else if(salesTotal>10.000){
        commisionRate = (commisionRate*100)/5;
        System.out.println("the commision rate is : " +commisionRate);
    }


}
}

commisionRate is a variable that depends from the user input salesTotal , you are reading the salesTotal but never using it to calculate the commisionRate CommisionRate是一个取决于用户输入salesTotal的变量,您正在读取 salesTotal 但从未使用它来计算commisionRate

you should be doing instead:你应该这样做:

 if(salesTotal <=10.000){
        commisionRate = (salesTotal *100)/2;
        System.out.println("the commision rate is : " +commisionRate);

    }
    else if(salesTotal>10.000){
        commisionRate = (salesTotal *100)/5;
        System.out.println("the commision rate is : " +commisionRate);
    }

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

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