谁能告诉我我的代码有什么问题吗?

时间:2018-11-09 16:45:00

标签: java methods return override return-value

import java.util.Scanner;

public class LeapYear {
    private static int value;
    private static int total;
    public static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        EnterYourNumbers();
        enterTotal();
        calculatePercentage();
    }

    public static int EnterYourNumbers() {
        System.out.println("Enter a number below\r");
        value = scanner.nextInt();
        System.out.println("Your number input was " + value);
        return value;

    }
    public static int enterTotal() {
        System.out.println("Print out your Total Number below");
        total = scanner.nextInt();
        System.out.println("Your total was " + total);
        return total;
    }
    public static void calculatePercentage() {
        double percentage = (value/total)*100;
        System.out.println("Your percentage is " + percentage + "%");
    }

}

输出是百分比= 0.0%,而不是20%。这是为什么?它应该返回变量,但是我显然已经搞砸了。

预先感谢

0 个答案:

没有答案