1 Replies - 259 Views - Last Post: 08 December 2011 - 09:56 PM Rate Topic: -----

#1 shannon_p  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 10-November 11

Illegal start of expression

Posted 08 December 2011 - 09:47 PM

  public static void main(String[] args) throws IOException {
       int [][] magic = new int [5][5];
       int i;
       int row = 5-1;
        int col = 5/2;
        int num = 0;
        int rowsum = 0;
	int colsum = 0;
	int diagsum = 0;
        int basicsum = 0;

        magic[row][col] = 1;
       Scanner kbd = new Scanner(System.in);
       String fname;
       
        for(row = 0; row < 5; row++)
            for(col = 0; col < 5; col++)
                magic[row][col]= 0;
        System.out.println("Enter the name of the file");
        fname = kbd.next();
        File ifile = new File(fname);
        Scanner infile = new Scanner(ifile);
        for(i = 0; i <5; i++){
        for (i = 2; i <= 25; i++) {
            if (magic[(row + 1) % 5][(col + 1) % 5] == 0) {
                row = (row + 1) % 5;
                col = (col + 1) % 5;
            }
            else {
                row = (row - 1 + 5) % 5;
            }
            magic[row][col] = i;
        }
        }
        for (i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                if (magic[i][j] < 10)  System.out.print(" ");  
                if (magic[i][j] < 100) System.out.print(" "); 
                System.out.print(magic[i][j] + " ");
            }
            System.out.println();
            if(checkDiags(basicsum, magic) && checkRowsCols(basicsum, magic)){  
             System.out.println("A magic Square!");  
        }  
         else 
                System.out.println("not a magic squrare");
            }  
            public static boolean checkRowsCols(int basicSum,int[][] magic){  
            int rowSum = 0;  
            int colSum = 0;  
            for(int i=0;i<5;i++){  
             rowSum = 0;  
           for(int j=0;j<5;j++){  
                rowSum+=magic[i][j];  
                colSum+=magic[j][i]; 
                if(rowSum!=basicSum && colSum!=basicSum){              
                return false;  
                }
                else
              colSum = 0;  
                rowSum =0;
              return true;  
          }
            } 
            }
         public static boolean checkDiags(int basicSum, int[][] magic){  
         int diag1 = 0;  
         int diag2 = 0;  
         for(int i=0;i<5;i++){  
            diag1+=magic[i][i];  
            diag2+=magic[i][5-1-i];  
       }  
          if(diag1!=diag2 || diag1!=basicSum){  
             return false; 
          }
          else
          return true;
    }   
          public static int getBasicSum(int[][] a){
          int sum = 0;  
          for(int i=0;i<5;i++){  
             sum+=a[0][i];  
            }  
         return sum; 
            }
}
}
}



everything is fine except for public boolean checkRowsCols... I am getting both an illegal start of expression and a method breakpoint error. Also, at the very end of my program on the second to last } I am getting a enum, interface, or class expected error. I thought maybe it was due to the loss of a } but I can't seem to figure it out.

Is This A Good Question/Topic? 0
  • +

Replies To: Illegal start of expression

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Illegal start of expression

Posted 08 December 2011 - 09:56 PM

Yes you miss one closing } of the main() before checkRowsCols(), you need to close main() before starting another method definition
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1