错误:解析时到达文件末尾

时间:2016-03-04 21:17:05

标签: java

我收到此错误:

  

错误:解析时到达文件末尾

我知道这意味着我需要在某个地方关闭花括号,但我已经尝试了一切。我认为第45行是需要关闭的支撑,但我不确定如何。这是一个程序,用于帮助找到制作用户输入的整数所需的最小数量的硬币。例如,37将产生2个季度,1个维度和2个便士。

import java.util.Scanner;
public class Change {
	public static void main(String[] args){

		Scanner sc = new Scanner (System.in);
Int n = sc.nextInt("Enter a positive integer" );
		int number1, number2; // Division operands
      int quotient;         // Result of division

	{if (QtrCnt > 0)

	if (QtrCnt > 1)
	System.out.println(QtrCnt + " quarters");
	else
	System.out.println(QtrCnt + " quarter");
}
if (DimeCnt > 0)
{
if (DimeCnt > 1)
System.out.println(DimeCnt + " dimes");
else
System.out.println(DimeCnt + " dime");
}
if (NicklCnt > 0)
{
if (NicklCnt > 1)
System.out.println(NicklCnt + " nickles");
else
System.out.println(NicklCnt + " nickle");
}
if (PennyCnt > 0);
{
if (PennyCnt > 1);
System.out.println(PennyCnt + " pennies");
System.out.println(PennyCnt + " penny");
}

int q = 25;
int d = 10;
int n = 5;
int p = 1;
if (a < 0);

System.out.println("ERROR");
{
 String (money >=25); { int numQuarters = money/ 25; }
 money -= numQuarters * 25;
 QtrCnt = (num1 - num1 % 25) / 25;
 num1 = num1 - QtrCnt * 25;

  String(money >=10); { int numDimes = money/ 10; }
 money -= numDimes * 10;
 DimeCnt = (num1 - num1 % 10) / 10;
num1 = num1 - DimeCnt * 10;

   String (money >=5); { int numNickles = money/ 5; }
  money -= numNickles * 5;
  NicklCnt = (num1 - num1 % 5) / 5;
num1 = num1 - NicklCnt * 5;

    String (money >=1); { int numPennies = money/ 1; }
  money -= numPennies * 1;
  PennyCnt = (num1 - num1 % 1) / 1;
num1 = num1 - PennyCnt * 1;
}
   }

1 个答案:

答案 0 :(得分:1)

是的,你实际上错过了该课程的结束括号。

你也有很多基本上没有做任何事情的括号。请记住,如果你没有把{紧接在if的()之后,它就不属于if语句。

我清理了你的代码并得到了这个:

import java.util.Scanner;

public class Change 
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner (System.in);
        Int n = sc.nextInt("Enter a positive integer" );
        int number1, number2; // Division operands
        int quotient;         // Result of division

        {   // <- Won't do anything
            if (QtrCnt > 0)
                if (QtrCnt > 1)
                    System.out.println(QtrCnt + " quarters");
                else
                    System.out.println(QtrCnt + " quarter");
        }

        if (DimeCnt > 0)
        {
            if (DimeCnt > 1)
                System.out.println(DimeCnt + " dimes");
            else
                System.out.println(DimeCnt + " dime");
        }

        if (NicklCnt > 0)
        {
            if (NicklCnt > 1)
                System.out.println(NicklCnt + " nickles");
            else
                System.out.println(NicklCnt + " nickle");
        }

        if (PennyCnt > 0);
        {
            if (PennyCnt > 1);
                System.out.println(PennyCnt + " pennies");
            System.out.println(PennyCnt + " penny");
        }

        int q = 25;
        int d = 10;
        int n = 5;
        int p = 1;

        if (a < 0);
            System.out.println("ERROR");

        { // <- Won't do anything
            String (money >=25); { int numQuarters = money/ 25; }
            money -= numQuarters * 25;
            QtrCnt = (num1 - num1 % 25) / 25;
            num1 = num1 - QtrCnt * 25;

            String(money >=10); { int numDimes = money/ 10; }
            money -= numDimes * 10;
            DimeCnt = (num1 - num1 % 10) / 10;
            num1 = num1 - DimeCnt * 10;

            String (money >=5); { int numNickles = money/ 5; }
            money -= numNickles * 5;
            NicklCnt = (num1 - num1 % 5) / 5;
            num1 = num1 - NicklCnt * 5;

            String (money >=1); { int numPennies = money/ 1; }
            money -= numPennies * 1;
            PennyCnt = (num1 - num1 % 1) / 1;
            num1 = num1 - PennyCnt * 1;
        }
   }
 // <- This is where you're missing the class bracket

请尝试改进您编写代码的方式,因为它确实可以帮助您快速找到这些错误。

请记住,我只是重新格式化了代码,我没有更改它的功能或检查它是否有效。