title: How to get the last number of an integer input
body: <p>Binary to decimal converter without the use of built-in Java methods. It must do this conversion automatically. When I get the last number of the integer during input it gives me a number format exception.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Homework02 {
  
      public static void main(String[] args) {
  
          Scanner keyboard = new Scanner(System.in);
  
          System.out.println("Enter an 8-bit binary number:");
          int binary = keyboard.nextInt();
          int copyBinary = binary;
          int firstDigit = Integer.parseInt(Integer.toString(copyBinary).substring(0, 1));
          int secondDigit = Integer.parseInt(Integer.toString(copyBinary).substring(1, 2));
          int thirdDigit = Integer.parseInt(Integer.toString(copyBinary).substring(2, 3));
          int fourthDigit = Integer.parseInt(Integer.toString(copyBinary).substring(3, 4));
          int fifthDigit = Integer.parseInt(Integer.toString(copyBinary).substring(4, 5));
          int sixthDigit = Integer.parseInt(Integer.toString(copyBinary).substring(5, 6));
          int seventhDigit = Integer.parseInt(Integer.toString(copyBinary).substring(6, 7));
          int eigthDigit = Integer.parseInt(Integer.toString(copyBinary).substring(7));
  
          firstDigit = firstDigit*128;
          secondDigit = secondDigit*64;
          thirdDigit = thirdDigit*32;
          fourthDigit = fourthDigit*16;
          fifthDigit = fifthDigit*8;
          sixthDigit = sixthDigit*4;
          seventhDigit = seventhDigit*2;
          eigthDigit = eigthDigit*1;
  
          System.out.println(firstDigit+" "+secondDigit+" " +thirdDigit+" "+fourthDigit+" "+fifthDigit+" "+sixthDigit+" "+seventhDigit+" "+eigthDigit);
  
          System.out.println(copyBinary + " in decimal form is " + (firstDigit+secondDigit+thirdDigit+fourthDigit+fifthDigit+sixthDigit+seventhDigit+eigthDigit));
      }
  
  }
  </code></pre>