Hello
Guys i working in a program that i enter strings
until the user write Stop, STOP, stop
how do i stop it
i did this
[I'm going out Today is hot I love to play it should print 1 I'm going out 2 Today is hot 3 I love to play.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello
Guys i working in a program that i enter strings
until the user write Stop, STOP, stop
how do i stop it
i did this
[I'm going out Today is hot I love to play it should print 1 I'm going out 2 Today is hot 3 I love to play.
Last edited by WantHelp; July 4th, 2011 at 01:50 PM.
Your posted code does NOT show any print statements. You need to show the code where the problem is.it didn't work!!!
Read the String class API doc for a method that may do what you want when comparing Strings with different cases.
Another problem: Use the equals method to compare String objects, not the == operator.
WantHelp are you deleting any posts? I can't see any of your attempted code & I'd like to help
In this case the code that was posted was mostly junk. It didn't have any print statements as the title implies. Mostly it was a bunch of if tests using == for Strings.
Posters who persistently remove their code from posts should be warned, and banned if they continue to do it.
I used KeyboardReader from TerminalIO, you can change it if you need too. Also change the array size as you need and modify it as you want, I don't know exactly what you're looking for. Hopefully my comments help you, good luck.
import TerminalIO.KeyboardReader; public class NumberStrings { public static void main (String[] args) { String[] phrases = new String[10]; // Create a string array to hold values you enter phrases[0] = "placeholder"; // Initialize the first position as a placeholder int x = 0; // Create an integer value used to update the array KeyboardReader reader = new KeyboardReader(); // Create a keyboard reader // Store the strings until the user enters "stop" while (true) { phrases[x] = reader.readLine(); phrases[x+1] = "placeholder"; // Test whether the current entry contains "stop" if (phrases[x].equalsIgnoreCase("stop")) { break; } else { x++; } } System.out.println(); // Create a line space // Print each entry for (int y = 0; y < x; y++) { System.out.println((y+1) + ". " + phrases[y]); } reader.pause(); // Prevent fly-by } }
Why???phrases[0] = "placeholder"; // Initialize the first position as a placeholder phrases[x+1] = "placeholder";
A. Don't spoonfeed code.
B. Don't spoonfeed code it if contains bad practises.
Also, your code will throw an ArrayIndexOutOfBoundsException if user never enters "stop".
Improving the world one idiot at a time!