-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumbersMagic.java
38 lines (32 loc) · 1022 Bytes
/
NumbersMagic.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
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class NumbersMagic {
public static int absolute(int x) {
if (x > 0) return x;
return -x;
}
public static boolean isPrime(int x) {
System.out.println("max: " + Math.round(Math.sqrt(x)));
for (int i = 2; i < Math.round(Math.sqrt(x)); i++ ) {
if (x % i == 0) return false;
}
return true;
}
public static double getHypoten(double a, double b) {
return Math.sqrt(a*a + b*b);
}
public static long getRandom() {
System.out.println(Math.random()* 100) ;
return Math.round(Math.random() * 1000);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println(absolute((x)));
System.out.println(isPrime((x)));
System.out.println(getHypoten(8, 15));
System.out.println(getRandom());
}
}