I want to change decimal to binary, octagonal, hexadecimal, By setting only one input(decimal) int i, I want to get 3 output: binary, octal, hexadecimal.
But my problem is that when I write 'while' once to change to binary using int i, I can't get proper answer about next 'while' to change to octagonal using int i.
I thought my code about octal was wrong, but when I set another int o, it worked properly...I think the result of first 'while' is used as input in next 'while'.
I wonder if I use 'while' once using int i, then can't I use that original int i in next 'while'?
I want to know how to get 3 output using only one input.
For example,
| input | output |
|---|---|
| 2017 | b 11111100001 |
| o 3741 | |
| h 7e1 |
It's my first time studying coding, so my question can be weird. Sorry:( Code below is I made using two input.
import java.util.Scanner;
public class LA {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int i = scn.nextInt();
String ab = "";
while (i > 0) {
ab = (i % 2) + ab;
i /= 2;
}
System.out.println("b " + ab);
int o = scn.nextInt();
String cd = "";
while (o > 0) {
cd = (o % 8) + cd;
o /=8;
}
System.out.println( "o " + cd);
}
}