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
1 1387
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... - get ')' expected System.out.print(+ spaceCount + " spaces and " totalCount + "total asccis");
-
}
You forgot to fix the combinations of Strings and variables...
a "+" is required....
Sign in to post your reply or Sign up for a free account.
Similar topics
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemisis |
last post by:
Fish.h
#ifndef FISH_H
#define FISH_H
#include <iostream>
#include <vector>
|
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...
|
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"
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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: 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...
| | |