This is my first post so if there are formatting issues, I'm sorry. So long story short, every time I compile this code in DrJava the interactions pane becomes unresponsive, but the program itself is fine.
import java.util.Scanner;
import java.lang.Math;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter words, enter STOP to stop the loop.");
ArrayList <String>words = new ArrayList
<String>();
boolean end = false;
while(end == false){
String stop = "STOP";
String word = "";
for(int i = 0; Objects.equals(stop, word); i++){
word = scan.nextLine();
if(Objects.equals(stop, word) && i > 2){
System.out.print(words.size());
words.remove(0);
words.remove(i);
System.out.println(words);
end = true;
} else if(Objects.equals(stop, word) && i < 2){
System.out.print(words.size());
System.out.println(words);
end = true;
} else {
words.add(i, word);
}
System.out.println();
}
}
}
}
The objective of this code is: Write a Java program that allows a user to input words at the command line. Your program should stop accepting words when the user enters "STOP". Store the words in an ArrayList. The word STOP should not be stored in the list.
Next, print the size of the list, followed by the contents of the list.
Then, remove the first and last words stored in the list, but only if the list has a length greater than two. Finally, reprint the contents of the list.
This is a class assignment, so I am not trying to get the answer to the coding problem itself, but rather just the reason the interactions pane isn't responding. Thanks in advance!