03) Write a program to read array A(4,4) and find : 1. The average of the second column. 2. Print even numbers under the main diagonal 3. Print negative numbers

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
i need the answer quickly
03) Write a program to read array A(4,4) and find:
1. The average of the second column.
2. Print even numbers under the main diagonal
3. Print negative numbers
Transcribed Image Text:03) Write a program to read array A(4,4) and find: 1. The average of the second column. 2. Print even numbers under the main diagonal 3. Print negative numbers
Expert Solution
Step 1

//Java Program for Average of Array Elements
import java.util.Scanner;
class javaExample
{
    public static void main(String[] args) 
    {
         Scanner sc = new Scanner(System.in);
         int i,j,row,col;
         float sum=0,average;
         System.out.println("Enter the number of rows:");
         row = sc.nextInt();
         System.out.println("Enter the number of columns:");
         col = sc.nextInt();
 
         int[][] mat = new int[row][col];
 
         System.out.println("Enter the elements of the matrix") ;
         for(i=0;i<row;i++)
        { 
          for(j=0;j<col;j++)
          { 
              mat[i][j] = sc.nextInt();
          }
        }
 
     System.out.println("The elements of the matrix") ;
     for(i=0;i<row;i++)
     { 
      for(j=0;j<col;j++)
      { 
        System.out.print(mat[i][j]+"\t");
      }
       System.out.println("");
     }
 
     for(i=0;i<row;i++)
     { 
        for(j=0;j<col;j++)
        { 
          sum = sum + mat[i][j];
        }
      }
 
      average=sum/(row*col);
     System.out.printf("AVERAGE of the elements of the matrix = %.2f",average) ;
    }
}

 

Output:

Enter the number of rows:3
Enter the number of columns:3
Enter the elements of the matrix
56
63
53
45
78
89
56
45
56
The elements of the matrix
56 63 53 
45 78 89 
56 45 56 
AVERAGE of the elements of the matrix = 60.11

steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education