-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
77 lines (49 loc) · 1.36 KB
/
Main.java
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
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.company;
import java.util.ArrayList;
import java.util.Random;
public class Main {
public static void main(String[] args) {
binaryFunc(14);
//factorial(4);
//func(10);
}
//שאלה 1
public static void binaryFunc(int num){
String res = "";
while (num !=0){
res += num % 2;
num/=2;
}
for (int i = res.length() - 1; i >=0; i--){
System.out.print(res.charAt(i));
}
}
//שאלה 2
public static void func(int num){
Random r=new Random();
int[] random=new int[5];
int[] distance=new int[5];
for (int i=0;i<random.length;i++){
random[i]=r.nextInt(100);
System.out.println(random[i]);
distance[i]= Math.abs(num-random[i]);
}
int min=distance[0];
num=min;
for(int i=0;i<random.length;i++){
if(min>distance[i]){
min=distance[i];
num=random[i];
}
}
System.out.println("min: "+num);
}
//שאלה 3
public static void factorial(int num) {
int res = 1;
for (int i = 1; i <= num; i++) {
res *= i;
}
System.out.println(res);
}
}