1. Engineering
  2. Computer Science
  3. please this code doesnt work please could some one tell...

Question: please this code doesnt work please could some one tell...

Question details

Please this code doesn't work please could some one tell me why it a illegal start expression and how to fix it? on line 52?


import java.util.Scanner;
public class PhoneKeyPads {
public static void main(String[] args)
Scanner scanner = new Scanner(System.in);
// Read the string from console
System.out.println("Enter a phone number as a string");
String inputPhone = scanner.nextLine();
String phoneNumber = "";
int phoneDigit = 0;
for (int i = 0; i<inputPhone.length();i++)
// convert each char to uppercase
char phoneChar=Character.toUpperCase
// check if char is a letter
// call getNumber method to get the number of a
// given uppercase letter
// append phone number with the phoneDigit
phoneNumber +=phoneDigit;
//append phone number with the phoneChar
phoneNumber += phoneChar;
System.out.println("The phone number is:"+ phoneNumber);
}// end of main
* This method will take character as an input and
* return the corresponding number as per phone keypad
* mapping
public static int getNumber(char ch) // it say illegal start of expression
// create digit to letter mapping string per
//phone keypads
final String digit2Chars="ABC";
final String digit3Chars="DEF";
final String digit4Chars="GHI";
final String digit5Chars="JKL";
final String digit6Chars="MNO";
final String digit7Chars="PQRS";
final String digit8Chars="TUV";
final String digit9Chars="WXYZ";
// check the char mapping
if (digit2Chars.indexOf(ch)>=0)
return 2;
if (digit3Chars.indexOf(ch)>=0)
return 3;
if (digit4Chars.indexOf(ch)>=0)
return 4;
if (digit5Chars.indexOf(ch)>=0)
return 5;
if (digit6Chars.indexOf(ch)>=0)
return 6;   
if (digit7Chars.indexOf(ch)>=0)
return 7;
if (digit8Chars.indexOf(ch)>=0)
return 8;
if (digit9Chars.indexOf(ch)>=0)
return 9;
return 0;
}//end of method
}//end of class

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution