Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. String input = "";
  2. String phoneNumber = "";
  3. boolean valid = true;
  4.  
  5. Scanner keyboard = new Scanner(System.in);
  6.  
  7. while(valid == true)
  8. {
  9. System.out.println("Please write a tellephone to know if it is valid");
  10. input = keyboard.next();
  11.  
  12. if("exit".equals(input))
  13. {
  14. break;
  15. }
  16.  
  17. for(int cont = 0; cont != input.length(); cont ++)
  18. {
  19. if(input.charAt(cont) != '(' && input.charAt(cont) != ')' && input.charAt(cont) != '-')
  20. {
  21. phoneNumber = phoneNumber + input.charAt(cont);
  22. }
  23. }
  24. float phone;
  25. try
  26. {
  27. phone = Float.parseFloat(phoneNumber);
  28. if(phoneNumber.length() == 10)
  29. {
  30. System.out.println("It is valid!");
  31. }
  32. else
  33. {
  34. System.out.println("It is invalid!");
  35. }
  36. }
  37. catch(NumberFormatException ex)
  38. {
  39. System.out.println("It is invalid!");
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement