In: Computer Science
Create a calculator in java without using the math library which converts an integer into a hexadecimal number.
// Java Code
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner input = new Scanner( System.in );
System.out.print("Enter an integer : ");
int num =input.nextInt();
// For storing remainder
int rem; // Variable Declaration
// For storing result
String str2="";
// Digits in hexadecimal number system
char
hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
while(num>0)
{
rem=num%16;
str2=hex[rem]+str2;
num=num/16;
}
System.out.println("Decimal to hexadecimal: "+str2);
}
}
Editor Snapshot:
Output Sapshot: