Text Editor Help!?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Text Editor Help!?!

**Hey! I'm really new to Java, so pls no hate or super complicated junk xD** Anyways, I've been making a text editor using an array. It looks like this. import static java.lang.System.*; import java.io.IOException; import java.util.NoSuchElementException; import java.util.Scanner; public class Activate { public static void main(String[] args) throws NoSuchElementException,IOException { String words[] = new String[5]; for(int i = 0; i < 5; i++) { words[i] = ""; } //while(true) { for(int i = 0; i < 5; i++) { out.print("> "); out.println(words[i]); } Scanner reader = new Scanner(in); out.print("Which line to replace? (1-5) "); int number = reader.nextInt(); reader.nextLine(); out.print("What to replace with: "); String repl = reader.nextLine(); words[number - 1] = repl; reader.close(); //} } } I want it to go back to the beginning of the main method like the first run, but the while loop (commented out) throws an error I can't seem to get rid of. Any help on this would be GREATLY appreciated. Thanks!!

9th Dec 2017, 3:34 AM
Polytiel
Polytiel - avatar
6 Answers
+ 3
I will try to help you.. 1) Have you tried to change the while's condition from true to a flag variable? let the user change its value within the loop. 2) Try to declare variables reader, number and repl outside the while loop and just modify their value inside (the same for close method). 3) Let me know the error message that you have. Excuse my english. :)
9th Dec 2017, 5:32 AM
Mauro Bastasini
Mauro Bastasini - avatar
+ 10
Hi, just a wee reminder, next time please use the Code Playground. It provides an easier way to write code and you can run it to see the output. If you use code playground and want to include it in your question, you can post the link. It'll make it easier for you.
9th Dec 2017, 5:44 AM
Learnsolo
+ 7
@MemeBiscuit No problem, just making sure that you knew
9th Dec 2017, 6:20 AM
Learnsolo
+ 3
@Gordie and @Mauro Bastasni Thank you! I declared the variables outside the loop, and removed the close statement. I dont understand why, but it worked :P Thanks!
9th Dec 2017, 5:44 AM
Polytiel
Polytiel - avatar
+ 2
Thats because you are declaring the same variables in the same scope
9th Dec 2017, 5:46 AM
Mauro Bastasini
Mauro Bastasini - avatar
+ 2
@<Learnsolo> my bad :D i wrote in on eclipse and had to transfer it over real quick.
9th Dec 2017, 5:46 AM
Polytiel
Polytiel - avatar