473,395 Members | 1,915 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,395 software developers and data experts.

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.println("Enter a word to be pluralized");
word = IO.readString();
word = word.toLowerCase();

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

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

else

word = word.concat("s");
IO.outputStringAnswer(word);

}
}
Jun 28 '07 #1
1 6221
r035198x
13,262 8TB
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.println("Enter a word to be pluralized");
word = IO.readString();
word = word.toLowerCase();

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

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

else

word = word.concat("s");
IO.outputStringAnswer(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 =.
Jun 28 '07 #2

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

Similar topics

1
by: denisb | last post by:
hello all, for a search engine, I'm looking for a regexp than can do the job it is just (!) a 's' problem (frequent in french) : I have a field 'thesaurus' in a table MySQL (3.23.56) ; I...
2
by: Steve - DND | last post by:
Just wondering if anyone out there has any code to convert a plural word to it's singular form and vice versa. Most of our database tables are named in a plural fashion. When we go to create...
2
by: Robert W. | last post by:
In my current work I noticed that I have several circumstances where I need to create little if/else constructs to handle the phrasing of a message. This typically involves a ternary situation like...
7
by: Bosconian | last post by:
This might seem like a trivial thing, but has anyone has come up with a better way of outputting a singular vs. plural string? For example: // default plural label $string = "appointments";...
11
by: elrondrules | last post by:
Hi Am pretty new to python and hence this question.. I have file with an output of a process. I need to search this file one line at a time and my pattern is that I am looking for the lines...
4
by: guate911 | last post by:
Does anyone know of an open source applictation or API I can connect to, that will allow me to find the plural of a word? For example, if I type in "mouse", I need it to find the plural.. "mice". ...
7
by: The Bicycling Guitarist | last post by:
If I have a foreign word, name or phrase in one of my pages, I use the lang attribute to specify the relevant language, e.g., <span lang="de">Manfred von Richthofen</span>. But what if I want to...
4
by: xhe | last post by:
I need to create a website and I want to filter out filthy words or swear words. To my surprise, it is difficult to find such a list from google. So if you have that list, can you please share...
1
by: HumanJHawkins | last post by:
Hi all, I need something stronger than LIKE or CONTAINS, but not so comprehensive as the FORMSOF(Field, INFLECTIONAL). I am looking to see which words from one list also exist in another....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.