Scanner in = new Scanner(System.in); System.out.print("Vvedite chislo a: "); String a = in.nextLine(); System.out.print("Vvedite chislo b: "); String b = in.nextLine(); int inta = Integer.parseInt(a, 2); int intb = Integer.parseInt(b, 2); 

Vvedite chislo a: 12

Vvedite chislo b: 23

Java.lang.NumberFormatException: For input string: "12" at java.base / java.lang.NumberFormatException.forInputString (NumberFormatException.java:65) at java.base / java.lang.Integer.parseInt (Integer.java:652) at edu.Atom.Main.main (Main.java:22)

  • 2
    In the binary number system can not be twos. - Sergey Gornostaev
  • @SergeyGornostaev so I want to translate into binary, that's why I specify 2 - Nikita Mishchenko
  • one
    @SergeyGornostaev I think I saw a deuce - αλεχολυτ

1 answer 1

You do not translate into a binary code, but do exactly the opposite; you want to convert a number from binary to decimal.

To translate into a binary code, you need to use the toBinaryString or toString method:

 Integer.toBinaryString(a); //где a - десятичное число с типом int //или Integer.toString(a, 2);