0

So, I'm working on this code for my Java class and I came to this issue that is bugging me, Sorry if it's a bit long, I'm new to Java coding.

import javax.swing.*;
public class DebugEight4
{
   public static void main(String[] args)
   {
      int x = 0, y;
      String array[] = new String[100];
      String entry;
      final String STOP = "XXX";
      StringBuffer message = new
          StringBuffer("The words in reverse order are\n");

      entry = JOptionPane.showInputDialog(null,
        "Enter any word\n" +
        "Enter " + STOP " when you want to stop"); 
      while(!(entry.equals(STOP)))
      {
         array[STOP] = entry;
         entry = JOptionPane.showinputDialog(null,
            "Enter another word\n" +
            "Enter " + STOP + " when you want to stop"); 
      }
      for(y = 0; y > 0; ++y)
      {
         message.append(array[y]);
         message.append("\n");
      }
      JOptionPane.showMessageDialog(null, message);
   }
}

I'm getting a DebugEight4.java:17: error: ')' expected "Enter " + STOP " when you want to stop"); (Arrow points to the space between STOP and " ) ^

DebugEight4.java:17: error: illegal start of expression "Enter " + STOP " when you want to stop"); (arrow points to the ')' ) ^

DebugEight4.java:23: error: ')' expected ("Enter " + STOP + " when you want to stop"); (Arrow points to the ;) ^

This is all one problem, and another problem I'm getting is with this:

DebugEight4.java:20: error: incompatible types array[STOP] = entry; required: int found: String (aarow points to STOP

DebugEight4.java:21: error: cannot find symbol entry = JOptionPane.showinputDialog(null, symbol: method

Sorry for this long post, but as I said I'm new to this and would like some help with this, thanks everyone!

2
  • 1
    1) Array index should be integer, not String Commented Nov 7, 2013 at 22:27
  • Not a compile error, but I'm pretty sure you didn't actually want for(y = 0; y > 0; ++y). Commented Nov 7, 2013 at 22:29

1 Answer 1

2

In this line, you forgot a +:

"Enter " + STOP " when you want to stop"); 

Change it to:

//              v
"Enter " + STOP + " when you want to stop"); 

Additionally, only an int can be the index of an array, but STOP is a String.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.