-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava
More file actions
65 lines (42 loc) · 759 Bytes
/
java
File metadata and controls
65 lines (42 loc) · 759 Bytes
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.*;
public class DEC_BIN {
public static int de;
public static int ost;
public static String bi ="";
public static StringBuffer sbf;
public static void vvod(){
System.out.println("Введите число");
Scanner sc = new Scanner(System.in);
if(sc.hasNextInt()){
de = sc.nextInt();
}
else {
System.out.println("Вы ввели не целое число");
}
}
public static void convert(int d) {
ost = de % 2;
if (ost==0){
bi += "0";
}
else{
bi += "1";
}
sbf = new StringBuffer(bi);
de = de / 2 ;
if (d==1){
return ;
}
else
{
convert(de);
}
//return;
}
public static void main(String[] args) {
vvod ();
System.out.print("DEC = " + de + "\n");
convert(de);
System.out.print("BIN = " + sbf.reverse()+ "\n");
}
}