Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i need help please!!!!

Status
Not open for further replies.

cindyg919

Programmer
Feb 10, 2001
17
US
I need help with the program I am doing.
I am writing a program that takes a one-line sentence as input and then outputs the following response: if the sentence ends with a question mark and the input contains even number of characters, then output the word "yes". If the sentence ends with a question mark and the input contains odd number of characters, then ouput the word "No". If the input sentence ends with an exclamation mark then output the word "Wow". In all other cases the program will output the string "You always say" followed by the input string enclosed in quotes. The output should be on one line.

The program has to be done in System.out.println
This is what i have so far but it doesnt work I am having trouble mainly with the if/else.

public class Questions
{
public static void main(String[] args)
{
string even, odd, exclamationMark, other;

System.out.println("Enter a phrase:");

if(even == 0 || ?)
{
System.out.println("yes");
}
else if(odd == 1 || ?)
{
System.out.println("No");
}
else if(!);
{
System.out.println("Wow");
}
else System.out.println(\""You always say" + other \");

even = SavitchInreadLineString();
odd = SavitchInreadLineString();
exclamationMark = SavitchInreadLineString();
other = SavitchIn.readLineString();
}
}

 
hello,
i can't actually give you the code but can hint you with some refreces of fuctions.

public boolean endsWith(String suffix);

is a java.lang .String method gives you idea of whether you have "?" or "!" on this .

there is another method called
tokeniger method which will let you know whether there are any tokens matchin the pattern you are seacthing and its default constructor checks for " " ie blank spaces so
these things will serve your pupose i feel

if you still any problem then mail me to
ksriniva@cal.cognizant.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top