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

In summary, an " ')' expected " error indicates that there is a missing closing parenthesis in the code. This is often caused by other syntactic errors or extra spaces between characters. In the given conversation, the error was caused by a space between `num' and `3' in the line of code. Once the space was removed, the error was fixed.
  • #1
bomba923
763
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
  • #2
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'.
 
  • #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!
 
  • #4
I still think it's the space between `num' and `3'.
 
  • #5
Ohhh--->that space?

How can I fix that? :redface:
 
  • #6
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:
 
  • #7
Many thanks! :smile:

Indeed that was the error!
 
Last edited:

What is the "Fixing "')' Expected" error in Java?

The "Fixing "')' Expected" error in Java is a common syntax error that occurs when a closing parenthesis is missing in a statement or expression. This error indicates that the compiler was expecting a closing parenthesis but instead found another character or reached the end of the statement.

What causes the "Fixing "')' Expected" error in Java?

The most common cause of the "Fixing "')' Expected" error in Java is a missing closing parenthesis in a statement or expression. This can be due to a typo or a mistake in the code logic. Another possible cause is forgetting to close a parenthesis in a previous statement, which results in the compiler expecting a closing parenthesis in the following statement.

How can I fix the "Fixing "')' Expected" error in Java?

To fix the "Fixing "')' Expected" error in Java, you need to identify the location of the error and add the missing closing parenthesis. You can also double-check your code for any typos or logic errors that may be causing the issue. Additionally, you can use an IDE or code editor with syntax highlighting to easily spot missing parentheses in your code.

How can I prevent the "Fixing "')' Expected" error in Java?

To prevent the "Fixing "')' Expected" error in Java, it is important to pay attention to parentheses when writing code. Always make sure that each opening parenthesis has a corresponding closing parenthesis, and vice versa. Also, using proper indentation and formatting can help make it easier to spot any missing parentheses in your code.

Are there any other common errors that are similar to "Fixing "')' Expected" error in Java?

Yes, there are other common errors that are similar to the "Fixing "')' Expected" error in Java. These include "Missing ')' or Extra ')'", "Missing '}' or Extra '}'", and "Missing ';' at the end of a statement". These errors all indicate a mismatch in opening and closing symbols, which can be easily fixed by identifying the location of the error and adding or removing the necessary symbols.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
334
  • Programming and Computer Science
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
992
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
2
Views
174
  • Programming and Computer Science
Replies
4
Views
3K
Back
Top