Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PhoneTest {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter a phone number in the (###) ###-#### format");
- String phoneNumber = input.nextLine();
- char ch = phoneNumber.charAt(0);
- char ch1 = phoneNumber.charAt(4);
- char ch2 = phoneNumber.charAt(5);
- char ch3 = phoneNumber.charAt(9);
- if (ch != '(' || ch1 != ')' || ch2 != ' ' || ch3 != '-')
- System.out.println("The phone number you entered was: " + phoneNumber + " This is an incorrect format.");
- else
- System.out.println("The phone number you entered was: " + phoneNumber + " This is in the correct format.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement