【发布时间】:2014-02-10 03:25:18
【问题描述】:
所以我正在为我的 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: 错误:解析时到达文件末尾
我能得到的任何帮助都会很棒。
【问题讨论】: