Skip to main content
added 104 characters in body
Source Link
P3trur0
  • 3.2k
  • 1
  • 15
  • 27

What about this?

public class BinaryToDecimal {
    public static void main(String[] args) {
        System.out.print("Input first binary number: ");
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        while(!"q".equalsIgnoreCase(line.trim())){
            System.out.print("Inputtry{
 first binary number: ");
            try{System.out.println(Integer.parseInt(line,2));
          
       System.out.print("Input next binary number: ");      line = in.nextLine();  
                System.out.println(Integerline = in.parseIntnextLine(n,2));
            }
            catch(Exception e){
                System.out.println("Not a binary number");
            }
        }
    }
}

What about this?

public class BinaryToDecimal {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        while(!"q".equalsIgnoreCase(line.trim())){
            System.out.print("Input first binary number: ");
            try{          
                 line = in.nextLine();
                System.out.println(Integer.parseInt(n,2));
            }
            catch(Exception e){
                System.out.println("Not a binary number");
            }
        }
    }
}

What about this?

public class BinaryToDecimal {
    public static void main(String[] args) {
        System.out.print("Input first binary number: ");
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        while(!"q".equalsIgnoreCase(line.trim())){
            try{
                System.out.println(Integer.parseInt(line,2));
                System.out.print("Input next binary number: ");          
                line = in.nextLine();
            }
            catch(Exception e){
                System.out.println("Not a binary number");
            }
        }
    }
}
Post Undeleted by P3trur0
Post Deleted by P3trur0
Source Link
P3trur0
  • 3.2k
  • 1
  • 15
  • 27

What about this?

public class BinaryToDecimal {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        while(!"q".equalsIgnoreCase(line.trim())){
            System.out.print("Input first binary number: ");
            try{          
                line = in.nextLine();
                System.out.println(Integer.parseInt(n,2));
            }
            catch(Exception e){
                System.out.println("Not a binary number");
            }
        }
    }
}