473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
1 2517
madhoriya22
252 100+
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

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

Similar topics

2
by: ankit | last post by:
I want to get the start and end of all the patterns mattched in regex. I know I can get it with start() and end() fn of matched objects. But re.search() return the match object of first matching...
2
by: dobbouk | last post by:
I'm getting these 2 errors and haven't got a clue whats causing them please java 43: illegal start of type for (i=0;i< Number_of_squares; i++) java 215 identifier expected } ...
12
by: psbasha | last post by:
Hi , Could anybody help me in fixing this problem.I am getting different results. Sample1 import re strLine =' 1 THRU 20 sList = re.findall('\d+ THRU \d+|\d+', strLine) print sList
2
by: =?Utf-8?B?Z2FkeWE=?= | last post by:
I have downloaded and installed the trial but the File New is greyed out so I can't get started! What have I not done that I need to do? --
4
by: rajesh619 | last post by:
I'm new to programming. I have created a servlet which retrieves values from the database after a value is put into the HTML page to which it is attached. But during compilation, it shows two errors....
3
by: gokulagopal | last post by:
I am sending the code please help me in finding the error and correct it.The code is below: import java.awt.*; import java.awt.event.*; class CalcFrame extends Frame { ...
2
by: mole40 | last post by:
Hello! I'm very new to writing java. And I keep getting the "Illegal Start of Type" error. I've tried everything to fix it. can anyone help me? import java.util.*; class ClockTalk { public...
1
by: John Luttig | last post by:
import java.awt.*; import java.awt.event.* ; import java.awt.image.*; import java.awt.geom.* ; import javax.swing.* ; import javax.swing.event.* ; public class NPCObject { public void...
2
by: Christina Arena | last post by:
I'm just starting to learn java as part of a class I am required to take as a math major. I am feeling completely lost. I guess we're supposed to learn this as independently as possible. I was...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.