Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.*;
- public class BinaryToDecimal {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println("Please enter either a binary number as a sequence of 1's and 0's or type 'quit' to exit the program");
- String bin = in.nextLine();
- String bin2 = bin.toLowerCase();
- int len = bin2.length();
- if (bin2.indexOf("quit") > -1 && len == 4){
- return;}
- while (bin2.indexOf("quit") > -1 && len != 4)
- {System.out.println("Input can't have letters besides specifically entering the word 'quit' to exit the program");
- bin2 = in.nextLine();}
- while (bin2.indexOf("quit") == -1){
- if (bin2.matches("\\d[01]+")){System.out.println("Testing testing 123");}
- else if (!bin2.matches("\\d[01]+")) {
- System.out.println("Input can't have numbers besides 1 and 0, or any letters if you have not decided to exit with the 'quit' command");
- bin2 = in.nextLine();}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement