fork download
  1. import java.util.Scanner;
  2.  
  3. class BinChange {
  4. public static void main(String args[]){
  5. Scanner input = new Scanner(System.in);
  6. System.out.println("Enter in only 1 and 0 and click enter for each time");
  7.  
  8. int[] bits = new int[16];
  9. for (int i = bits.length - 1; i >= 0; i--) {
  10. bits[i] = input.nextInt();
  11. }
  12.  
  13. int sum = 0;
  14. for (int i = bits.length - 1; i >= 0; i--) {
  15. int value = bits[i] << i;
  16. System.out.println(value);
  17. sum += value;
  18. }
  19.  
  20. System.out.println("The value is: " + sum);
  21. }
  22. }
Success #stdin #stdout 0.05s 711680KB
stdin
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
stdout
Enter in only 1 and 0 and click enter for each time
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
1
The value is: 5