Results 1 to 3 of 3
  1. #1
    drinkme is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default conversion between binary and decimal systems

    Hi people, i'm working on this task. Netbeans gives me this error message: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
    at zaklady.Vstup.main(Vstup.java:40)


    Java Code:
    package zaklady;
    
    //import java.io.BufferedReader;
    //import java.io.IOException;
    //import java.io.InputStreamReader;
    import java.io.*;
    
    
    
    public class Vstup {
        public static void main(String[] args)  {
    String vstup;
    BufferedReader in;
    in = new BufferedReader(new  InputStreamReader(System.in));
    try{vstup = in.readLine(); }
    catch(IOException e) {vstup="";}
    int cislo=Integer.valueOf(vstup);
    int zbytek=cislo%2;
    //System.out.println(zbytek);
    cislo=cislo/2;
    //System.out.println(cislo);
    String retezec=String.valueOf(zbytek);
    do
    {
        zbytek=cislo%2;
        cislo=cislo/2;
        String vysledek=String.valueOf(zbytek);
       // System.out.println(retezec);
        //System.out.println(vysledek);
        retezec=retezec+vysledek;
    }while(cislo!=0);
    //System.out.println(retezec);
    
          
            for (int i = retezec.length(); i!=0 ; i--) {
                String keyTop = retezec.substring(i-1, i);
                String vysledek2="";
                vysledek2=vysledek2+keyTop;
               }
    
           System.out.println(vysledek2);
        }
    }
    Thank you for your tips.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,039
    Rep Power
    6

    Default Re: conversion between binary and decimal systems

    In your do/while loop and for loop, you declare a String type vysledek. That variable's scope is limited to the loops in which it was declared. So the last statement above can't locate the symbol.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    drinkme is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default Re: conversion between binary and decimal systems

    Yes,that's it! Thanks!

Similar Threads

  1. Replies: 2
    Last Post: 02-22-2013, 07:10 PM
  2. Binary to Decimal conversion
    By mrashi12 in forum New To Java
    Replies: 4
    Last Post: 12-31-2011, 08:52 PM
  3. Replies: 5
    Last Post: 08-25-2011, 08:32 PM
  4. Help for numbering systems (binary)
    By jimmy91 in forum New To Java
    Replies: 2
    Last Post: 06-12-2011, 03:25 PM
  5. Binary-to-Decimal Conversion (Precision Problem)
    By shadowfax57 in forum New To Java
    Replies: 4
    Last Post: 09-07-2010, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •