我不知道为什么我的程序给我花括号错误我怎样才能解决这个问题 ?请帮忙

问题描述

|| 我已经完成了从1周开始的所有编码,其中包括TestEmployee类,在该类中,我必须检查整数范围,字符串长度以及是否为数字。我已完成所有工作,但使用的方法找不到任何问题....但是在程序最后一行的最后两个花括号中却给我错误)...请帮忙。 这是我的代码:
import java.util.Scanner;
import java.lang.Object;
import java.awt.*;
import java.text.*;

public class TestEmployeePayRoll {


    public static void main(String[] args)

    {
    String EmployeeID,FullName,result;
    double oursWorked;
    int counter = 0;

    Scanner input = new Scanner(System.in);

    do{
        do{


    System.out.println(\"Enter the Employee ID number: \"+ \" \");
    EmployeeID = input.nextLine();

    if(EmployeeID.trim().length()>5)

        {

            System.out.println(\" EmployeeID number must be exactly 5: \" + \" \");

        }
    }

     while(EmployeeID.length() > 5);

    System.out.println(\"Enter the First Name: \");
    String FirstName = input.nextLine();

    System.out.println(\"Enter Last Name: \"+ \" \");
    String LastName = input.nextLine();

    do
    {

    System.out.println(\"Enter the Pay Category: \"+ \" \");

    double PayCategory = input.nextDouble();

    Double pay = new Double(PayCategory);

    if(pay.isNaN())
    {
        System.out.println(\"****Enter a valid Pay Category***\");
    }
        if(!(PayCategory >0 && PayCategory <5))
        {
        System.out.println(\"Pay Category must be between 1 and 4\");
        }

        while(PayCategory < 1 || PayCategory > 4);

        do
        {
            System.out.println(\"Enter the number of hours worked: \");
            double HoursWorked = input.nextDouble();

            Double hours = new Double(HoursWorked);
            if(hours.isNaN())
        {
            System.out.println(\"---Enter a valid hours value---\");
        }

        if(!(HoursWorked >1 && HoursWorked <80))
         {
            System.out.println(\"---Enter value between 1 and 80---\");
         }

        while(HoursWorked < 1 || HoursWorked > 80);

        EmployeePayRoll obj1 = new EmployeePayRoll(FirstName,LastName,EmployeeID,HoursWorked,PayCategory);

        DecimalFormat fmt = new DecimalFormat(\"###,##0.00\");

        System.out.println(\"\\n-----------------------------------------------------\");

        System.out.println(\"\\n The pay details for:\" + obj1.getName() + \"\\t\\t\\t\" + \"ID:\" + EmployeeID);

        System.out.println(\"\\n-----------------------------------------------------\");

        System.out.println(\"Pay Category: \\t\\t\\t\" + obj1.getPayCategory());
        System.out.println(\"Hours Worked: \\t\\t\\t\" + obj1.getHoursWorked());
        System.out.println(\"Pay Rate: \\t\\t\\t\" + obj1.getPayRate());
        System.out.println(\"Gross Pay:  \\t\\t\\t\" + \"$\"+fmt.format(obj1.getGrossPay()));
        System.out.println(\"Tax Payable:  \\t\\t\\t\" + \"$\"+fmt.format(obj1.getTaxPayable()));
        System.out.println(\"\\t\\t\\t\\t---------\");
        System.out.println(\"Net Pay: \\t\\t\\t\" + \"$\" + fmt.format(obj1.getNetPay()));
        System.out.println(\"\\n------------------------------------------------------\");
        System.out.println();
        System.out.println(\"\\n +Process another employee? (Y/N)\");
        result = input.next();

        }
                     while (result.equals(\"Y\")||result.equals(\"y\"));

    }} //this two curly giving me errors saying 
         //reached end of file parsing/while expected...
         //It doesn\'t work if I add or delete curly braces..
谢谢     

解决方法

        似乎第57行缺少紧接在其前面的右括号。
while (PayCategory < 1 || PayCategory > 4)
解决此问题后,您将不必担心PayCategory的范围。 可能我还会推荐具有格式化功能的友好IDE吗? IntelliJ在这方面做得很好(Eclipse和其他工具也是如此)。     ,        看起来像这样:
 while(HoursWorked < 1 || HoursWorked > 80);
应该:
 while(HoursWorked < 1 || HoursWorked > 80){
换句话说,while循环在开始时需要用一个大括号\“ {\”,在结束时需要用一个括弧\“} \”。     ,        错误消息为您提供所需的提示。 \“到达文件末尾\”意味着当javac在寻找while循环的末尾时,它在找到文件之前就到达了文件末尾。在这种情况下,问题在于while循环线上的问题,这是人们遇到的常见错误。 如果您格式化代码以使每个块都缩进,则可以很容易地看到这样的错误。例如:
public int myFunction()
    {

    if (thing)
        {
            ...blah...
            ...blah...
        }
    }
    else
    {
        while
            ...blah...
            ...blah...
        }
    }
}   
这样一来,很容易看到事情没有排到一起以捕捉错误。不同的人在花括号的位置使用不同的样式,但是总是将每个代码块缩进另一个级别可以使这种情况更容易发现。     ,        在以下两个while语句中结束的do循环似乎没有右括号...
while(PayCategory < 1 || PayCategory > 4);
while(HoursWorked < 1 || HoursWorked > 80);
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...