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

错误:解析时到达文件末尾-java,java,binary,Java,Binary,所以我正在为我的java课程做家庭作业。我试图编写一个简单的程序,将4字节的二进制数转换为十进制数。现在,我承认我使用了我在搜索中找到的一些行。所以,我不确定我的代码到底发生了什么。我的消息来源如下 import java.util.Scanner; public class B2Dconversion { public static void main (String [] args) { System.out.println("Hello, I am so gl

所以我正在为我的java课程做家庭作业。我试图编写一个简单的程序,将4字节的二进制数转换为十进制数。现在,我承认我使用了我在搜索中找到的一些行。所以,我不确定我的代码到底发生了什么。我的消息来源如下

import java.util.Scanner;

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

    System.out.println("Hello, I am so glad you stopped by my little place I call home.");
    System.out.println("I have been told I have many talents, but the one that I can do for you now.");
    System.out.println("What I would like you to do is enter a 4-byte binary number and I will convert it for you into decimal.");
    try 
            {                                    //thread to sleep for the specified number of milliseconds
            Thread.sleep(5000);
            } catch (java.lang.InterruptedException ie) {
            }
    System.out.println("..... Oh you don't know what a 4-byte binary number is?");
    System.out.println("That is just a 4 digit number consisting of any combination of 1's and 0's.");
    System.out.println("i.e. 0001 or 1111 or 1010 etc...");
    System.out.println("So go ahead and enter any 4 digit number in the space below and I will convert it to its binary counterpart.");

    int binary1, decimal1; // declaration of the integer variables

    binary1 = keyboard.nextLine();
    decimal1 = Interger.parseInt(binary1,2); // converts binary to decimal see java documentation at http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#parseInt%28java.lang.String,%20int%29

    System.out.println("You entered " + binary1); // confirmation of the input
    System.out.println("Abra-Cadabra");
    System.out.println("Bippity Boppity");
    System.out.println("Beep, Bop, Boop, eeerrrrr");

    System.out.println("Now that is done the results are ");
    System.out.println( + decimal1);
    }
编译时我得到1个错误,唯一显示的是B2Dconversion.java:42:error:解析时到达文件末尾


我能得到的任何帮助都会很好。

您没有平衡括号。这就是为什么你会犯这样的错误。您必须在文件末尾使用
}
字符关闭该类。如果你用谷歌搜索到了那个错误。您可以在stackoverlow上找到类似的问题


所以这就是我为了让程序正常运行而做的事情

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

    System.out.println("Hello, I am so glad you stopped by my little place I call home.");
    System.out.println("I have been told I have many talents, but the one that I can do for you now.");
    System.out.println("What I would like you to do is enter a 4-byte binary number and I will convert it for you into decimal.");
    try 
            {                                    //thread to sleep for the specified number of milliseconds
            Thread.sleep(5000);
            } catch (java.lang.InterruptedException ie) {
            }
    System.out.println("..... Oh you don't know what a 4-byte binary number is?");
    System.out.println("That is just a 4 digit number consisting of any combination of 1's and 0's.");
    System.out.println("i.e. 0001 or 1111 or 1010 etc...");
    System.out.println("So go ahead and enter any 4 digit number in the space below and I will convert it to its binary counterpart.");

    String binaryNumber;
    int eights, fours, twos, ones, decimalNumber; // declaration of the integer variables

    Scanner keyboard = new Scanner(System.in);

    binaryNumber = keyboard.nextLine();
    decimalNumber = 0;
    decimalNumber = decimalNumber+(binaryNumber.charAt(0)-'0')*8;
    decimalNumber = decimalNumber+(binaryNumber.charAt(1)-'0')*4;
    decimalNumber = decimalNumber+(binaryNumber.charAt(2)-'0')*2;
    decimalNumber = decimalNumber+(binaryNumber.charAt(3)-'0')*1;

    System.out.println("You entered " + binaryNumber); // confirmation of the input
    System.out.println("Abra-Cadabra");
    System.out.println("Bippity Boppity");
    System.out.println("Beep, Bop, Boop, eeerrrrr");
    try 
            {                                    //thread to sleep for the specified number of milliseconds
            Thread.sleep(5000);
            } catch (java.lang.InterruptedException ie) {
            }
    System.out.println("Now that is done the results is ");
    System.out.println(decimalNumber);
    }
}

谢谢你的关注。现在来看看真正的乐趣。。。。不过我有一个新的错误B2Dconversion.java:34:错误:找不到符号d1=integer.parint(b1,2);symbol:variable integer location:class B2Dconversion“我必须做一些更改,所以这里是我认为它正在引用的代码片段。内部b1,d1;//整型变量扫描器键盘的声明=新扫描器(System.in);b1=键盘.nextInt();d1=整数parseInt(b1,2)<代码>d1simbol不在您发布的代码中。真奇怪。实际错误是什么?对不起,我修改了代码以简化变量,您没有定义“键盘”。在使用之前定义它。这不是定义“键盘”吗?扫描仪键盘=新扫描仪(System.in);