程序没有显示出来

时间:2014-10-30 18:55:49

标签: java

import java.util.Scanner;

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

    Scanner reader = new Scanner(System.in);

    double totalRegularHours;
    double overTimeHours;
    overTimeHours = reader.nextDouble();

    double hourlyWage;
    hourlyWage = reader.nextDouble();

    double overTimePay;
    overTimePay = overTimeHours * (1.5 * hourlyWage);

    double totalWeeklyPay;


    System.out.print("Enter the Hourly Wage: ");
    hourlyWage = reader.nextDouble();

    System.out.print("Enter the total amount of regular hours: ");
    totalRegularHours = reader.nextDouble();

    System.out.print("Enter the total amount of over time hours: ");
    overTimeHours = reader.nextDouble();

    totalWeeklyPay = totalRegularHours * hourlyWage + overTimePay;

    System.out.print("The Total weekly pay is $" );
    System.out.println(totalWeeklyPay);
    }

}

由于某种原因,程序不会在eclipse上运行(显示)。我也尝试在CMD上运行它,结果相同。没有提到错误。

我无法弄清楚有什么问题可以有人请帮忙吗?

1 个答案:

答案 0 :(得分:0)

这对你有用。首先声明您的变量,并且在您提示用户之前不要从扫描仪中读取:

import java.util.Scanner;

public class Project3x4 {
    public static void main(String [] args){
        Scanner reader = new Scanner(System.in);

        double totalRegularHours;
        double overTimeHours;
        double hourlyWage;
        double totalWeeklyPay;


        System.out.print("Enter the Hourly Wage: ");
        hourlyWage = reader.nextDouble();

        System.out.print("Enter the total amount of regular hours: ");
        totalRegularHours = reader.nextDouble();

        System.out.print("Enter the total amount of over time hours: ");
        overTimeHours = reader.nextDouble();

        double overTimePay;
        overTimePay = overTimeHours * (1.5 * hourlyWage);

        totalWeeklyPay = totalRegularHours * hourlyWage + overTimePay;

        System.out.print("The Total weekly pay is $" );
        System.out.println(totalWeeklyPay);
    }
}