You need to use an array to print out a decimal number as a hexadecimal number There is an error when you input the value with scanner and print it out in the if statement. I'd appreciate it if you watched it.
==================================
private static int count;
private static Object intput;
public static void main(String[] args) {
// // TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
char[] hex_out = new char[4];
int remainder = 0;
System.out.println ("Enter an integer value between 1 and 20000");
int x = scanner.nextInt();
for (int i=0; i<4; i++) {
remainder = x%16;
x=x/16;
if (remainder>9) {
hex_out[3-i] = (char)(remainder-10+'A');
System.out.println("" + hex_out[str.charAt(i)]);
//It works well until you enter a value with scan, but there is an error here.
}
else if (remainder<10) {
hex_out[i] = (char)(remainder-0);
System.out.println("" + hex_out[str.charAt(i)]);
}
}
}
}
System.out.println("" + hex_out[str.charAt(i)]);
//It works well until you enter a value with scan, but there is an error here.
In str.charAt(i), the variable str is not declared anywhere in the code.
But there will be a compilation error because there is no variable, but it is strange that the value is entered as scan~
Oh, str is String str = " korea";
I declared it above, but the previous output is different
I erased the code, uploaded it, and erased it
Please enter a value It's a situation where there's an error if you type it up
© 2024 OneMinuteCode. All rights reserved.