Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Error error: ';' expected validatePhone(phoneNumber) { ^ Why I am getting the above error? If I add a ; after validatePhone(phoneNumber) I get 8

Java Error

error: ';' expected validatePhone(phoneNumber) { ^

Why I am getting the above error? If I add a ; after validatePhone(phoneNumber) I get 8 different errors.

I'm trying to write this line of code as a method but I'm doing something wrong:

//validate user input and display error message validatePhone(phoneNumber) { return phoneNumber.matches( "\\([1-9]\\)\\d{3}-[1-9]\\d{3}-\\d{4}" )

============================================================================================================================

Entire program

class Sample { public static void main(String[] args) { String phoneNumber; String[] tokens; Boolean validatePhone;

//get user input Scanner scanner = new Scanner (System.in); System.out.println(" Please enter phone number: "); String.phoneNumber = scanner.nextLine();

//validate user input and display error message validatePhone(phoneNumber) { return phoneNumber.matches( "\\([1-9]\\)\\d{3}-[1-9]\\d{3}-\\d{4}" ) } //Validate Phone Number if (validatePhone(phone)){ //process phone number String[]tokens = phoneNumber.split("-|\\(|\\)"); System.out.println("1 "+tokens[1]); System.out.println("2 "+tokens[2]); //tokenized first 3 digits of phone number System.out.println("3 " +tokens[3]);

} else System.out.println("Error!");

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

3. Yesim is really supportive when other students are upset.

Answered: 1 week ago