Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String input = "";
- String phoneNumber = "";
- boolean valid = true;
- Scanner keyboard = new Scanner(System.in);
- while(valid == true)
- {
- System.out.println("Please write a tellephone to know if it is valid");
- input = keyboard.next();
- if("exit".equals(input))
- {
- break;
- }
- for(int cont = 0; cont != input.length(); cont ++)
- {
- if(input.charAt(cont) != '(' && input.charAt(cont) != ')' && input.charAt(cont) != '-')
- {
- phoneNumber = phoneNumber + input.charAt(cont);
- }
- }
- float phone;
- try
- {
- phone = Float.parseFloat(phoneNumber);
- if(phoneNumber.length() == 10)
- {
- System.out.println("It is valid!");
- }
- else
- {
- System.out.println("It is invalid!");
- }
- }
- catch(NumberFormatException ex)
- {
- System.out.println("It is invalid!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement