-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType_Conversion.java
More file actions
47 lines (46 loc) · 1.04 KB
/
Copy pathType_Conversion.java
File metadata and controls
47 lines (46 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.Scanner;
class Type_Conversion
{
public static void main(String args[])
{
int a;
Scanner sc=new Scanner(System.in);
System.out.println("enter a no");
a=sc.nextInt();
Type_Conversion obj=new Type_Conversion();
obj.dec_bin(a);
obj.dec_oct(a);
obj.dec_hex(a);
}
void dec_bin(int n)
{
String x="";
for(int a=n;a>0;a=a/2)
{
x=(a%2)+x;
}
System.out.println("The decimal equivalent is "+x);
}
void dec_oct(int n)
{
String x="";
for(int a=n;a>0;a=a/8)
{
x=(a%8)+x;
}
System.out.println("The octal equivalent is "+x);
}
void dec_hex(int n)
{
String x="";
char arr[]={'A','B','C','D','E','F'};
for(int a=n;a>0;a=a/16)
{
if(a%16>9)
x=arr[(a%16)-10]+x;
else
x=(a%16)+x;
}
System.out.println("The hexadecimal equivalent is "+x);
}
}