+ 1

What can scanners scan instead of input. And how do I use it?

Hello. I was trying to make an program that converts binary numbers to decimal numbers, and then convert back to binary and display on the screen. But when I tried to scan the Binary number column by column I couldn't do it because I didn't know how to fill the parameter in the new scanner object. Please help me. long binary1; long binary2; Scanner scan = new Scanner(System.in); System.out.println("Input first binary number."); binary1 = scan.nextLong(); System.out.println("Input second binary number."); binary2 = scan.nextLong(); long[] powersOf2 = { 2^0,2^1,2^2,2^3,2^4,2^5,2^6,2^7,2^8,2^9,2^10,2^11,2^12,2^13,2^14,2^15 }; Scanner binaryscan = new Scanner(I dont know what to place here); I want to later make an array with integers from the each column. Many thanks.

10th Jul 2017, 5:24 AM
MassiveMayhem
2 Respostas
+ 2
you can make a method in your class like this static void showNum(long s ,long d ){ // write the the operation that will run on input here long r ; r= //the output System.out.println(r); } in the main : showNum(s,d ); //and replace "s,d" with "binary1,binary2" .......... this is according what i understanded from your question
10th Jul 2017, 7:44 AM
Ahmed Mohammed Ahmed Khodary
Ahmed Mohammed Ahmed Khodary - avatar
0
scanner is just for your input you can make multiple inputs by pressing enter on the input screen? after you run your program your input will be compared with your code once.
10th Jul 2017, 9:11 AM
D_Stark
D_Stark - avatar