Advertisement
lleu

Untitled

Sep 20th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PhoneTest {
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner(System.in);
  6.  
  7. System.out.println("Enter a phone number in the (###) ###-#### format");
  8. String phoneNumber = input.nextLine();
  9.  
  10. char ch = phoneNumber.charAt(0);
  11. char ch1 = phoneNumber.charAt(4);
  12. char ch2 = phoneNumber.charAt(5);
  13. char ch3 = phoneNumber.charAt(9);
  14.  
  15.  
  16. if (ch != '(' || ch1 != ')' || ch2 != ' ' || ch3 != '-')
  17. System.out.println("The phone number you entered was: " + phoneNumber + " This is an incorrect format.");
  18. else
  19. System.out.println("The phone number you entered was: " + phoneNumber + " This is in the correct format.");
  20.  
  21. }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement