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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hunternora
    New Member
    • Mar 2008
    • 1

    #1

    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.JOp tionPane;

    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.sho wInputDialog (null, "Enter a sentence...plea se");
    size = charInput.lengt h();

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

    while (position < size)
    {
    c = charInput.charA t(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.prin t("There are " + aCount + " a's, " +eCount + " e's, ");
    System.out.prin t(iCount+ " i's, " + oCount+ " o's, and " + uCount);
    System.out.prin t("u's and " + iCount+ " i's, " + oCount+ " o's, and ");
    System.out.prin t(+ uCount+ " u's and " + otherCount + " other letters and");
    get ')' expected System.out.prin t(+ spaceCount + " spaces and " totalCount + "total asccis");
    }

    }


    Any ideas? Thanks
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by Hunternora
    I'm just trying to count letters, by type etc. What am I doing wrong here?

    import javax.swing.JOp tionPane;

    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.sho wInputDialog (null, "Enter a sentence...plea se");
    size = charInput.lengt h();

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

    while (position < size)
    {
    c = charInput.charA t(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.prin t("There are " + aCount + " a's, " +eCount + " e's, ");
    System.out.prin t(iCount+ " i's, " + oCount+ " o's, and " + uCount);
    System.out.prin t("u's and " + iCount+ " i's, " + oCount+ " o's, and ");
    System.out.prin t(+ uCount+ " u's and " + otherCount + " other letters and");
    get ')' expected System.out.prin t(+ 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...

    Code:
    [B]get ')' expected[/B] System.out.print(+ spaceCount + " spaces and " totalCount + "total asccis");
    }
    You forgot to fix the combinations of Strings and variables...
    a "+" is required....

    Comment

    Working...