Making words Plural

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tryce430
    New Member
    • Jun 2007
    • 1

    #1

    Making words Plural

    Hi,

    I've actually been working on a homework assignment which asks me to turn words into their plural forms. The first task is to check if the words are more than 3 characters and end in "us". If it does I just take out the us and add an "i" at the end. Otherwise I just throw an "s" to the end of the word. I think I got most of the program down, but for some reason it gives me an error with &&. Could someone take a look at my code and tell me what I may be doing wrong regarding && or anything else?

    public class Plurals
    {
    public static void main(String[] args)
    {
    String word;

    System.out.prin tln("Enter a word to be pluralized");
    word = IO.readString() ;
    word = word.toLowerCas e();

    int length = word.length();
    if (length > 3 && word.charAt(len gth-1) = "s" &&
    word.charAt(len gth-2) = "u")

    word = word.substring( 0,length-2) + "i";

    else

    word = word.concat("s" );
    IO.outputString Answer(word);

    }
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by tryce430
    Hi,

    I've actually been working on a homework assignment which asks me to turn words into their plural forms. The first task is to check if the words are more than 3 characters and end in "us". If it does I just take out the us and add an "i" at the end. Otherwise I just throw an "s" to the end of the word. I think I got most of the program down, but for some reason it gives me an error with &&. Could someone take a look at my code and tell me what I may be doing wrong regarding && or anything else?

    public class Plurals
    {
    public static void main(String[] args)
    {
    String word;

    System.out.prin tln("Enter a word to be pluralized");
    word = IO.readString() ;
    word = word.toLowerCas e();

    int length = word.length();
    if (length > 3 && word.charAt(len gth-1) = "s" &&
    word.charAt(len gth-2) = "u")

    word = word.substring( 0,length-2) + "i";

    else

    word = word.concat("s" );
    IO.outputString Answer(word);

    }
    }
    1.) When posting code please use code tags.
    2.) Make use of ( ) to make your code more readable and correct.
    3.) Character literals are enclosed in single quotes ' ' not in " ".
    4.) The comparison operator is == not =.

    Comment

    Working...