By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,963 Members | 1,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,963 IT Pros & Developers. It's quick & easy.

plz help me with my code--i am getting one illegal start of expression

P: 1
it is a bit jacked up, but copy and paste it into an IDE(i use jGRASP) plz help me...it worked just fine before I added the menu..you can e-mail me if you have any <Removed>
import java.util.*;
public class VowelsConsCounter
{
public int i= list.indexOf(object);
public static char getMenuSelection();
{
String input;
char selection;
Scanner keyboard = new Scanner(System.in);
System.out.println("a) Count the number of vowels in the string.");
System.out.println("b) Count the number of consonants in the string.");
System.out.println("c) Count the number of characters in the string.");
System.out.println("d) Count the number of whitespaces in the string.");
System.out.println("e) Exit the program.");

input = keyboard.nextLine();
selection = input.charAt(0);
while(Charecter.toLowerCase(selection) < 'a'|| Charecter.toLowerCase(selection) >'e')
{
System.out.print("Only enter a,b,c,d or e");
input = keyboard.nextLine();
selection = input.charAt(0);
}
return selection;
}
VowelCons vc = new VowelCons(input);
{

do{
selection=getMenuSelection();
// public static void main(String[] args) {
for(int i = 0; i < 100; i++) {

switch(Character.toLowerCase(selection))
{
case 'a': System.out.println("Number of vowels: "+countVowels(text)); // display the number of vowels
case 'b': System.out.println("Number of constanants: "+countConsonants(text)); // display the number of consonants
case 'c': System.out.println("Number of characters: "+text.length()); // display the number of printable characters
case 'd': System.out.println("Number of spaces: "+countSpaces(text));
}
}while(Character.toLowerCase(selection) !='e');



static int countConsonants(String s)
{
char[] array = s.toCharArray();
int counter=0;
for (int i = 0; i < array.length; i++)
{
if(isConsonant(array[i]))
{
counter++;
}
}
return counter;
}
char[] vowel={'a', 'e', 'i', 'o', 'u'}; // set the definition of a vowel. This could easily be changed to consonants by just replacing the characters present
char[] consonant={'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'}; // set the definition of a consonant
public static void main(String[] args)
{
System.out.println("Enter a word, or phrase (Maximum 300 words):"); // request the user input the text to be analysed
Scanner sc = new Scanner(System.in); // read the input from Scanner into sc
String text = sc.nextLine(); // read the text input by the user into the Scanner sc
}

static boolean isConsonant(char c)
{
for (int i = 0; i < consonant.length; i++)
{
if(c==consonant[i])
{
return true;
}
}
return false;
}

static int countVowels(String s) // method to count the number of vowels input
{
char[] array = s.toCharArray();
int counter=0;
for (int i = 0; i < array.length; i++)
{
if(isVowel(array[i]))
{
counter++;
}
}
return counter;
}

static boolean isVowel(char c)
{
for (int i = 0; i < vowel.length; i++)
{
if(c==vowel[i])
{
return true;
}
}
return false;
}

static int countSpaces(String s) // method to count the number of white spaces
{
int count=0;
char[]a=s.toCharArray();
for (int i = 0; i < a.length; i++)
{
if(32==(int)a[i]) {
count++;
}
}
return count;
}
}
Jul 23 '07 #1
Share this Question
Share on Google+
1 Reply


madhoriya22
100+
P: 252
public static char getMenuSelection();
{
String input;
char selection;
Scanner keyboard = new Scanner(System.in);
System.out.println("a) Count the number of vowels in the string.");
System.out.println("b) Count the number of consonants in the string.");
System.out.println("c) Count the number of characters in the string.");
System.out.println("d) Count the number of whitespaces in the string.");
System.out.println("e) Exit the program.");

input = keyboard.nextLine();
selection = input.charAt(0);
while(Charecter.toLowerCase(selection) < 'a'|| Charecter.toLowerCase(selection) >'e')
{
System.out.print("Only enter a,b,c,d or e");
input = keyboard.nextLine();
selection = input.charAt(0);
}
return selection;
}
VowelCons vc = new VowelCons(input);
{

do{
selection=getMenuSelection();
// public static void main(String[] args) {
for(int i = 0; i < 100; i++) {

switch(Character.toLowerCase(selection))
{
case 'a': System.out.println("Number of vowels: "+countVowels(text)); // display the number of vowels
case 'b': System.out.println("Number of constanants: "+countConsonants(text)); // display the number of consonants
case 'c': System.out.println("Number of characters: "+text.length()); // display the number of printable characters
case 'd': System.out.println("Number of spaces: "+countSpaces(text));
}
}while(Character.toLowerCase(selection) !='e');
luk here in ur code(see quotes above)...... u hav put semicolon b4 the start of method(getMenuSelection();) body......after that u hav put curly braces at wrong places..........like after * VowelCons vc = new VowelCons(input);* this line........check these curly braces and put it in right place.........learn to debug ur code...........
Jul 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.