2014-02-09 2 views
-1

Итак, я работаю над своей домашней работой для своего класса java. Я пытаюсь закодировать простую программу, которая преобразует 4-байтовое двоичное число в десятичное. Теперь, я признаю, что я использовал некоторые строки, которые я нашел в поисках. Итак, я не совсем уверен, что происходит с моим кодом. Мой источник ниже.ошибка: достигнут конец файла при разборе - java

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: ошибка: достигнут конец файла во время разбора

Любая помощь я могу получить было бы здорово.

ответ

1

У вас нет сбалансированных круглых скобок. вот почему вы получаете эту ошибку. вам необходимо закрыть класс с символом } в конце файла. если вы столкнулись с этой ошибкой. Вы можете найти подобные вопросы на stackoverlow

Reached End of file while parsing

Java compile error: "reached end of file while parsing }"

+0

Спасибо за ловить это. Теперь для настоящего удовольствия .... У меня есть новая ошибка. 'B2Dconversion.java:34: ошибка: не удается найти символ d1 = Interger.parsInt (b1,2); символ: переменная Interger местоположение: класс B2Dconversion ' Мне пришлось внести некоторые изменения, так что вот фрагмент кода, на который я верю, ссылается. \t \t int b1, d1; // объявление целочисленных переменных \t \t \t \t Сканер клавиатуры = новый сканер (System.in); \t \t b1 = keyboard.nextInt(); \t \t d1 = Interger.parseInt (b1,2); – RationalSolutions

+0

'd1' simbol нет в вашем размещенном коде. это странно. Какова фактическая ошибка? – lakshman

+0

Извините, я изменил код, чтобы упростить переменные, – RationalSolutions

0

Так это то, что я в конечном итоге делает, чтобы получить программу для работы

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); 
    } 
} 
Смежные вопросы