-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathBinaryNumbers.java
More file actions
30 lines (28 loc) · 925 Bytes
/
Copy pathBinaryNumbers.java
File metadata and controls
30 lines (28 loc) · 925 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
package binary_numbers;
import java.io.*;
import java.util.*;
public class BinaryNumbers {
public static void main(String[] args) throws IOException {
String out = "YES";
String str;
FileReader file = new FileReader("input.txt"); // Считывание данных из файла
Scanner sc = new Scanner(file);
str = sc.nextLine();
int strInt = Integer.valueOf(str);
if(strInt <= 0){
out = "NO";
}else{
while(strInt > 1){
if(strInt%2 == 0){ // Проверка четности остатка
strInt = strInt / 2; // Следующее число
}else{
out = "NO";
break;
}
}
}
FileWriter fileOut = new FileWriter("output.txt");
fileOut.write(out);
fileOut.close();
}
}