- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecToHex.java
More file actions
Latest commit
20 lines (20 loc) · 536 Bytes
/
Copy pathDecToHex.java
File metadata and controls
20 lines (20 loc) · 536 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
importjava.util.Scanner;
classDecToHex
{
publicstaticvoidmain(Stringargs[])
{
Scannerinput = newScanner( System.in );
System.out.print("Enter a decimal number : ");
intnum =input.nextInt();
intrem;
Stringstr2="";
charhex[]={'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);
input.close();
}
}