Looping...
Hey again,
I was wondering how I could take this program I made, which when a user enters in a sentence and contains a '?' and is even it will output YES if it's odd and with a '?' it will output NO and if it ends with a '!' it will output WOW and anything else it will just output, "you always say this " + text (the string the user entered). Anyways, how could I make the program loop that allows the user to repeat this until the user indicates that he wants the program to end?
public class IfElse2
{
public static void main(String[] args)
{
System.out.println("Please enter a one line sentence.");
String text = SavitchIn.readLine();
int length = text.length();
if (text.trim().endsWith("?"))
if ((length % 2) == 0) {
System.out.println("Yes");
}
else
{
System.out.println("No");
}
else if (text.trim().endsWith("!"))
{
System.out.println("Wow");
}
else
{
System.out.println("You always say this, \"" + text + "\"");
}
}
}
I was wondering how I could take this program I made, which when a user enters in a sentence and contains a '?' and is even it will output YES if it's odd and with a '?' it will output NO and if it ends with a '!' it will output WOW and anything else it will just output, "you always say this " + text (the string the user entered). Anyways, how could I make the program loop that allows the user to repeat this until the user indicates that he wants the program to end?
public class IfElse2
{
public static void main(String[] args)
{
System.out.println("Please enter a one line sentence.");
String text = SavitchIn.readLine();
int length = text.length();
if (text.trim().endsWith("?"))
if ((length % 2) == 0) {
System.out.println("Yes");
}
else
{
System.out.println("No");
}
else if (text.trim().endsWith("!"))
{
System.out.println("Wow");
}
else
{
System.out.println("You always say this, \"" + text + "\"");
}
}
}
