Exercise
Hexadecimal and binary
Objetive
Write a java program to ask the user for a number an display it both in hexadecimal and binary. It must repeat until the user enters 0.
Example Code
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n;
do
{
System.out.print("Enter a number:");
n = Integer.parseInt(new Scanner(System.in).nextLine());
if (n != 0)
{
System.out.print("Hexadecimal: ");
System.out.println(String.valueOf(n, 16));
System.out.print("Binary: ");
System.out.println(String.valueOf(n, 2));
}
} while (n != 0);
}
}