Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.*;
  3.  
  4. public class BinaryToDecimal {
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner(System.in);
  7. 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");
  8. String bin = in.nextLine();
  9. String bin2 = bin.toLowerCase();
  10. int len = bin2.length();
  11.  
  12.  
  13. if (bin2.indexOf("quit") > -1 && len == 4){
  14. return;}
  15.  
  16. while (bin2.indexOf("quit") > -1 && len != 4)
  17. {System.out.println("Input can't have letters besides specifically entering the word 'quit' to exit the program");
  18. bin2 = in.nextLine();}
  19.  
  20. while (bin2.indexOf("quit") == -1){
  21. if (bin2.matches("\\d[01]+")){System.out.println("Testing testing 123");}
  22. else if (!bin2.matches("\\d[01]+")) {
  23. 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");
  24. bin2 = in.nextLine();}
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement