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
[Code :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.
Printable View
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
[Code :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.
Your posted code does NOT show any print statements. You need to show the code where the problem is.Quote:
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.
Code :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???Code java: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".