Need help modifying code for hex conversion
Hi everyone. I'm new to Java and look forward to learning alot from here.
Currently I have a little problem with my code. I need to modify my existing java code which converts a base 10 value to base 10 and below. I need help modifying my code to allow for hex conversion also. My instructions are: Modify your program to handle base conversions up to base 16 (hexadecimal). Use if statements to substitute letters for numbers when the remainders are 10 or greater (for example, a remainder of 10 should be represented as “A”).
My code is the following:
I do not need a complete rewrite, but an addon to the code to allow the conversion.
import java.util.*; // needed for Scanner
public class Converter
public static void main (String [ ] args)
// Use this Scanner to read from the keyboard
Scanner input = new Scanner(System.in);
String answer = "";
System.out.print("Enter base 10 value to convert: ");
int value = input.nextInt();
System.out.print("Enter base to translate into: ");
int n = input.nextInt();
quotient = value / n;
remainder = value % n;
value = quotient;
answer = remainder + answer;
System.out.println("Answer: " +answer);
Thank you for your help.