0
public int[][] fileRead(String fileName);
{
  Scanner problem = new Scanner(new File(fileName));
  int m = 9; 
  int [][] tgrid = new int[m][m]; 
  while(input.hasNextInt()){
    for (int i=0;i<m;i++){
      for (int j=0;j<m;j++)
        a[i][j] = input.nextInt();
    }
  }

For some reason this code is giving two syntax errors... The errors are as below.

2 errors found:
File: C:\Documents and Settings\s2813788\My Documents\Downloads\1005ICTAssignment\SudokuDriver.java  [line: 81]
Error: Syntax error on token "(", ; expected
File: C:\Documents and Settings\s2813788\My  Documents\Downloads\1005ICTAssignment\SudokuDriver.java  [line: 81]
Error: Syntax error on token ")", delete this token

I don't see anything wrong with the method header or anything like that :| Any help would be appreciated.

3
  • 2
    can you tell as what line is line 81? Commented Sep 27, 2012 at 6:31
  • public int[][] fileRead(String fileName) Commented Sep 27, 2012 at 6:33
  • @Ben Gittins Post your full function source ,in this code we could see the right curly braces were also missing for function ending statement. Commented Sep 27, 2012 at 6:47

6 Answers 6

7

You have a semicolon after your method arguments.

public int[][] fileRead(String fileName);
{

Remove it:

public int[][] fileRead(String fileName)
{
Sign up to request clarification or add additional context in comments.

7 Comments

+1 also method's last curly brace is remaining, no return statement
code public int[][] fileRead(String fileName) { Scanner problem = new Scanner(new File(fileName)); int m = 9; int [][] tgrid = new int[m][m]; while(input.hasNextInt()){ for (int i=0;i<m;i++){ for (int j=0;j<m;j++) a[i][j] = input.nextInt(); } } return grid; } code
81. The declaration public int[][] fileRead(String fileName)
There is no issue there (unless you still need to remove the semicolon). Are you sure it isn't the result of a missing bracket earlier in your code?
No have been through and checked the missing brackets there aren't any open brackets. Has left me quite stumped :S
|
3

Remove the semicolon at the end of the first line:

public int[][] fileRead(String fileName);
----------------------------------------^

Also make sure all previous functions are closed. Where is the ending } for the main function? Also make sure you indent all your code correctly; good indentation will make it much easier to spot this error.

Comments

1

Remove semicolon in the first line.

Comments

1

if this isnt a typo, you have a semicolon(;) on your first line of the code

   public int[][] fileRead(String fileName);

remove that

public int[][] fileRead(String fileName)

Comments

1

The function definition should not have semi colon at end , please remove it , Follow the coding style as declaring the braces at the end of function definition line so you can avoid such syntax errors very easily here is the link

As:

     public int[][] fileRead(String fileName);

Change To:

     public int[][] fileRead(String fileName){

Comments

0

You need to remove the semicolon after the method definition.

public int[][] fileRead(String fileName);

And you are missing return statement for your method.

2 Comments

The whole method does have a Return statement. Thanks
-1 its not declaration, it is method definition and he has not posted his whole method code.

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.