473,326 Members | 2,133 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,326 software developers and data experts.

Why am I getting these errors? ( : expected , ')' expected )

I'm just trying to count letters, by type etc. What am I doing wrong here?

import javax.swing.JOptionPane;

public class Asg3
{
public static void main(String[] args)
{

int aCount=0, eCount=0, iCount=0, oCount=0, uCount=0, upperCount=0;
int lowCount=0, spaceCount=0, otherCount=0, totalCount=0;

char currentChar;
char c;
int position= 0,size =0;
String charInput;
charInput = JOptionPane.showInputDialog (null, "Enter a sentence...please");
size = charInput.length();

// now that everything has a value, lets get a loop going

while (position < size)
{
c = charInput.charAt(position);

switch (c)
{

Get : expected case 'b':case 'B':case 'c':case 'C':case 'd':case 'D':case 'f':case 'F';
otherCount++;
break;
case 'f':case 'F':case 'g':case 'G':case 'h':case 'H':case 'j':case 'J':
otherCount++;
break;
case 'k':case 'K':case 'l':case 'L':case 'm':case 'M':case 'n':case 'P':
otherCount++;
break;
case 'q':case 'Q':case 'r':case 'R':case 's':case 'S':case 't':case 'T':
otherCount++;
break;
case 'v':case 'V':case 'w':case 'W':case 'x':case 'X':case 'y':case 'Z':
otherCount++;
break;
case '.':case '!':case '?':case ',':case '$':case '@':case '&':case ':':
otherCount++;
break;
case 'a':case 'A':
aCount++;
break;
case 'e':case 'E':
eCount++;
break;
case 'i':case 'I':
iCount++;
break;
case 'o':case 'O':
oCount++;
break;
case 'u':case 'U':
uCount++;
break;
Get : expected case ' ';
spaceCount++;
break;

}


position++;
}
totalCount= size;

System.out.print("There are " + aCount + " a's, " +eCount + " e's, ");
System.out.print(iCount+ " i's, " + oCount+ " o's, and " + uCount);
System.out.print("u's and " + iCount+ " i's, " + oCount+ " o's, and ");
System.out.print(+ uCount+ " u's and " + otherCount + " other letters and");
get ')' expected System.out.print(+ spaceCount + " spaces and " totalCount + "total asccis");
}

}


Any ideas? Thanks
Mar 24 '08 #1
1 1387
sukatoa
539 512MB
I'm just trying to count letters, by type etc. What am I doing wrong here?

import javax.swing.JOptionPane;

public class Asg3
{
public static void main(String[] args)
{

int aCount=0, eCount=0, iCount=0, oCount=0, uCount=0, upperCount=0;
int lowCount=0, spaceCount=0, otherCount=0, totalCount=0;

char currentChar;
char c;
int position= 0,size =0;
String charInput;
charInput = JOptionPane.showInputDialog (null, "Enter a sentence...please");
size = charInput.length();

// now that everything has a value, lets get a loop going

while (position < size)
{
c = charInput.charAt(position);

switch (c)
{

Get : expected case 'b':case 'B':case 'c':case 'C':case 'd':case 'D':case 'f':case 'F';
otherCount++;
break;
case 'f':case 'F':case 'g':case 'G':case 'h':case 'H':case 'j':case 'J':
otherCount++;
break;
case 'k':case 'K':case 'l':case 'L':case 'm':case 'M':case 'n':case 'P':
otherCount++;
break;
case 'q':case 'Q':case 'r':case 'R':case 's':case 'S':case 't':case 'T':
otherCount++;
break;
case 'v':case 'V':case 'w':case 'W':case 'x':case 'X':case 'y':case 'Z':
otherCount++;
break;
case '.':case '!':case '?':case ',':case '$':case '@':case '&':case ':':
otherCount++;
break;
case 'a':case 'A':
aCount++;
break;
case 'e':case 'E':
eCount++;
break;
case 'i':case 'I':
iCount++;
break;
case 'o':case 'O':
oCount++;
break;
case 'u':case 'U':
uCount++;
break;
Get : expected case ' ';
spaceCount++;
break;

}


position++;
}
totalCount= size;

System.out.print("There are " + aCount + " a's, " +eCount + " e's, ");
System.out.print(iCount+ " i's, " + oCount+ " o's, and " + uCount);
System.out.print("u's and " + iCount+ " i's, " + oCount+ " o's, and ");
System.out.print(+ uCount+ " u's and " + otherCount + " other letters and");
get ')' expected System.out.print(+ spaceCount + " spaces and " totalCount + "total asccis");
}

}


Any ideas? Thanks
Please inclose the code you have posted in codetags...

About your problem, You forgot to check all cases that must end with a colon, not semi-colon...

Expand|Select|Wrap|Line Numbers
  1. get ')' expected System.out.print(+ spaceCount + " spaces and " totalCount + "total asccis");
  2. }
You forgot to fix the combinations of Strings and variables...
a "+" is required....
Mar 25 '08 #2

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
1
by: skhairnar | last post by:
Hi All, We are getting following error while compiling sources with SUN WS6U2, any idea how to resolve this error? "/opt/SUNWspro/WS6U2/include/CC/Cstd/rw/rwstderr.h", line 39: Error: namespace...
0
by: Si | last post by:
I'm writing an HttpModule to intecept web method calls and retrieve custom authentication information from their SOAP headers. I have the httpModules tag in web.config and that appears to be...
3
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you...
1
by: Paul Taylor | last post by:
Hello, I wonder if anyone can help with this. I have an ASP.NET 2.0 site that runs correctly on the local machine inside or outside of the IDE. When I build the site, it produces some warning...
2
by: donkeyboy | last post by:
All, I've tried the jythonc compiler to try and create an applet to see how it works, but I get a number of Java compile errors that are way above my knowledge. Does anyone know what any of the...
4
nemisis
by: nemisis | last post by:
Fish.h #ifndef FISH_H #define FISH_H #include <iostream> #include <vector>
18
by: Lance Wynn | last post by:
One of my server has been compromised from this virus, and I can't seem to block it out! I have shut down the infected server, but I need to figure out how to check for this, and stop it. The...
9
by: beet | last post by:
Hi, I am really not good at c/c++. Some simple code.. #include <stdio.h> #include <stdlib.h> #include <math.h> #include "simlibdefs.h"
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.