-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisBinary.java
More file actions
42 lines (32 loc) · 726 Bytes
/
Copy pathisBinary.java
File metadata and controls
42 lines (32 loc) · 726 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
// Program to check if the given input of integer numbers is binary or not.
package JavaConceptOfTheDay;
import java.util.Scanner;
public class isBinary {
public static void isBinary(int num){
int b = num;
boolean isBinary = true;
while(b != 0){
int temp = b % 10;
if(temp > 1){
isBinary = false;
}
else
b = b/10;
break;
}
if(isBinary){
System.out.println("Binary Number.");
}
else{
System.out.println("Not a binary number.");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("Enter the string of numbers : ");
int a = in.nextInt();
in.close();
isBinary(a);
}
}