RequiemDream
RequiemDream

Reputation: 31

2 errors with Java program

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!

Upvotes: 0

Views: 563

Answers (1)

rgettman
rgettman

Reputation: 178263

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.

Upvotes: 2

Related Questions