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);
}
}
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);
}
}
Comment