-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5a
37 lines (36 loc) · 936 Bytes
/
5a
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
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.lang.Math;
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("enter a binary number");
String binary = keyboard.nextLine();
int bin_len = binary.length();
int counter =0;
for (int i=0;i<bin_len;i++)
{
String check_string = binary.substring(i,i+1);
Boolean zero = check_string.contains("0");
Boolean one = check_string.contains("1");
if (zero)
{
counter++;
}
else if (one)
{
counter++;
}
else
{
System.out.println("NOT BINARY");
return;
}
}
System.out.println(binary + " is binary");
}
}