Fixing "')' Expected" Error in Java: What Causes It?

  • Context: Java 
  • Thread starter Thread starter bomba923
  • Start date Start date
  • Tags Tags
    Error Java Short
Click For Summary

Discussion Overview

The discussion revolves around a specific Java programming error, namely the " ')' expected " error, which participants are trying to diagnose and fix. The focus is on understanding the potential causes of this error within the context of a code snippet provided by one participant.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant inquires about the meaning of the " ')' expected " error and questions their use of parentheses in a specific line of code.
  • Another participant suggests that such errors may stem from earlier syntactic mistakes and highlights a potential issue with a space between `num` and `3` in the code.
  • A participant shares the complete code to provide context for the error and reiterates the specific error message encountered.
  • Some participants continue to emphasize the space issue as the likely cause of the error.
  • A later reply humorously suggests a method to fix the space issue, indicating a light-hearted approach to the problem.
  • One participant expresses gratitude and confirms that removing the space resolved the error.

Areas of Agreement / Disagreement

Participants generally agree that the space between `num` and `3` is the cause of the error, with one participant confirming that fixing it resolved their issue. However, there is some initial uncertainty about the nature of the error and whether it could be due to other syntactic mistakes.

Contextual Notes

There may be additional syntactic issues in the provided code, such as the use of `Int.parseInt` instead of `Integer.parseInt`, but these are not addressed in the discussion.

Who May Find This Useful

Individuals learning Java programming, particularly those encountering syntax errors, may find this discussion helpful.

bomba923
Messages
759
Reaction score
0
What does an " ')' expected " error signify? How did I not use parentheses correctly?

The error is in this line:

System.out.println(num1 + " " + num2 + " " + num 3 + " " + num4 + " " + num5) ;

What possible mistake can there be in parentheses?
 
Technology news on Phys.org
Such errors can often be symptoms of other syntactic mistakes. An error on a previous line could do it, but I bet it's really that nifty space you have between `num' and `3'.
 
The program is, as follows:
-----------------------------------
import javax.swing.JOptionPane ;

public class DigitSpacer {

public static void main(String args[]) {

String input;
int num0;
int num1;
int num2;
int num3;
int num4;
int num5;

input = JOptionPane.showInputDialog("What is the number?");

num0 = Int.parseInt(input);

num1 = Math.floor(num0 / 10000);

num2 = Math.floor((num0 - 10000 * num1) / 1000);

num3 = Math.floor((num0 - 10000 * num1 - 1000 * num2 ) / 100);

num4 = Math.floor( (num0 - 10000 * num1 - 1000 * num2 - 100 * num3 ) / 10);

num5 = num0 - 10000 * num1 - 1000 * num2 - 100 * num3 - 10 * num4 ;

System.out.println( num1 + " " + num2 + " " + num 3 + " " + num4 + " " + num5 );

System.exit(0);

}//main
}//DigitSpacer
--------------------------------------------------------
The only error is that "')' expected error" for some reason
regarding the line with System.out.println

*In another trial, I deleted the spaces, but I keep getting the same error!
 
I still think it's the space between `num' and `3'.
 
Ohhh--->that space?

How can I fix that? :redface:
 
Well, you place your cursor just to the left of the three (and thus to the right of the offending space), and press your backspace key! :biggrin:
 
Many thanks! :smile:

Indeed that was the error!
 
Last edited:

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 14 ·
Replies
14
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
10K