-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIf27.java
More file actions
29 lines (27 loc) · 845 Bytes
/
If27.java
File metadata and controls
29 lines (27 loc) · 845 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
package ifdirect;
import java.util.Scanner;
public class If27 {
/**
* x - haqiqiy soni kiritiladi
* 0 - agar x<0
* 1 - [0..1), [2..3) ...
* -1 - [1..2), [3..4) ...
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Sonni kiriting: ");
double x = scanner.nextDouble();
/* Algoritm: x = 20.5
* 1. sonning butun qismi olinadi 1
* 2. 2ga qoldigli bo'lamiz va qoldig'i olinadi 20%2=0
* 3. qoldiq == 0 -> 1
* aks holda -1
* */
if (x < 0) System.out.println(0);
else {
int butunQism = (int) x; // casting - double to int 20.7 -> 20
if (butunQism % 2 == 0) System.out.println(1);
else System.out.println(-1);
}
}
}