WHAT IS WRONG WITH THIS CODE?? Something with illegal start of expression

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

WHAT IS WRONG WITH THIS CODE?? Something with illegal start of expression

 

import java.util.Random; 

public class FamilyName_2Dim {
    
    public static void main(String[] args) {
    
    //random class object
    Random rand = new Random();
    
    //declare and initiate variables
    int i, j, k;
    int min = 10;
    int max = 75;
    
    //define 2D array (5 by 5)
    int array[][]=new int[5][5];

    //iterate for loop
    for(i=0;i<5;i++) {
        for(j=0;j<5;j++) {
            
            //generate random numbers from 10 to 75
            array[i][j]=rand.nextInt(max - min + 1) + min;
        }
    }
    
    //display text
    System.out.println(" 1) Output the array elements");
    
    //add space
    System.out.println();
    
    //iterate for loop
    for(i=0;i<5;i++) {
        for(j=0;j<5;j++) {
            
            //display array
            System.out.print("\t" + array[i][j] + "\t");
        }
        
        //add space
        System.out.println();
    }
    //declare and initialize variable
    int sumofprime = 0;
    
    //iterate for loop
    for(i=0;i<5;i++) {
        for(j=0;j<5;j++) {
            
            //declare and initialize variable
            int factor = 0;
            for(k=1;k<=array[i][j];k++) {
                
                //count the factors of the element in the array
                if(array[i][j]%k==0)
                    factor += 1;
            }
                //if the number of factors is 2 then the element is prime, so 
                if(factor == 2)
                
                    //find out the sum of such elements                                       
                    sumofprime += array[i][j];
        }
    }
    //display text
    System.out.println("\n 2) Output the sum of prime numbers in the array \n\t" + sumofprime);
    
    //display text
    System.out.println("\n 3) Output the elements in the main diagonal");
    
    //iterate for loop
    for(i=0;i<5;i++) {
        for(j=0;j<5;j++) {
            
            //elements at indexes (0,0) (1,1) (2,2) etc are diagonals
            if(i==j)
            
                //display elements where i=j                                                          
                System.out.print("\t" + array[i][j] + " ");
        }
    }

    //declare and initialize variable
    int sumbelowdiagonal = 0;
    
    //iterate for loop
    for(i=0;i<5;i++) {
        
        //find out elements below the diagonal
        for (j=i-1;j>=0;j--) {
        
            //find out the sum
            sumbelowdiagonal = sumbelowdiagonal + array[i][j];              
          }
    }
    
    //add space
    System.out.println();
    
    //display text
    System.out.println("\n 4) Output the sum of elements below the diagonal \n\t" + sumbelowdiagonal);

    //declare and initialize variable
    int sumabovediagonal = 0;
    
    //iterate for loop
    for(i=0;i<5;i++) {
        
        //find out elements below the diagonal
          for (j=i-1;j>=0;j--) {
              
              //find out the sum
            sumabovediagonal= sumbelowdiagonal + array[j][i];              
          }
    }
    
    //display text
    System.out.println("\n 5) Output the sum of elements above the diagonal \n\t" + sumabovediagonal);
    
    //display text
    System.out.println("\n 6) Output the odd numbers below the diagonal \n\t");
    
    //iterate for loop
    for(i=0;i<5;i++) {
        
        //find out elements below the diagonal
        for (j=i-1;j>=0;j--){ 
              
              //check if the element is odd
            if(array[i][j]%2!=0)                                            
                  
                  //display the elements
                  System.out.print("\t" + array[i][j] + " ");                       
          }
    }
    //add space
    System.out.println();
    
    //display text
    System.out.println("\n 7) Output the even numbers above the diagonal \n\t");
    
    //iterate for loop
    for(i=0;i<5;i++) {
        
        //find out elements below the diagonal
          for (j=i-1;j>=0;j--) {

            //check if the element is even
            if(array[j][i]%2==0)                                            /
                  
                  //display the elements
                  System.out.print("\t" + array[j][i] + " ");                      
      }
    }
  }
}

 

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Introduction to Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY