public class dr { public static void main(String args[]) { int m, n, i, j; Scann
ID: 3669058 • Letter: P
Question
public class dr
{
public static void main(String args[])
{
int m, n, i, j;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();
int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[]= new int[m];
int sum1[]= new int[n];
int avg[]= new int[m];
int avg1[]= new int[n];
System.out.println("Enter the elements of first matrix");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
first[i][j] = in.nextInt();
for(int x=0; x<m; x++)
{
for(int y=0; y<n; y++)
{
sum[x] += table[x][y];
avg[x]=sum[x]/n;
}
}
for ( int x = 0; x < m; x++ )
{
for ( int y = 0; y < n; y++ )
System.out.print( table[x][y] + " " );
System.out.println( "row avg is " + avg[x] );
}
for(int x=0; x<n; x++)
{
for(int y=0; y<m; y++)
{
sum1[x] += table[x][y];
avg1[x]=sum[x]/n;
}
}
for ( int x = 0; x < n; x++ )
{
for ( int y = 0; y < m; y++ )
System.out.print( table[x][y] + " " );
System.out.println( "col avg is " + avg1[x] );
}
}
}
why I am not able to compile this program, it showing too many errors
Explanation / Answer
In program some syntax errors while using for loop
In this program some of Curve braces({) miss in for loop
So check once
public class dr
{
public static void main(String args[])
{
int m, n, i, j;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();
int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[]= new int[m];
int sum1[]= new int[n];
int avg[]= new int[m];
int avg1[]= new int[n];
System.out.println("Enter the elements of first matrix");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
first[i][j] = in.nextInt();
for(int x=0; x<m; x++)
{
for(int y=0; y<n; y++)
{
sum[x] += table[x][y];
avg[x]=sum[x]/n;
}
}
for ( int x = 0; x < m; x++ )
{
for ( int y = 0; y < n; y++ ){
System.out.print( table[x][y] + " " );
System.out.println( "row avg is " + avg[x] );
}
}
for(int x=0; x<n; x++)
{
for(int y=0; y<m; y++)
{
sum1[x] += table[x][y];
avg1[x]=sum[x]/n;
}
}
for ( int x = 0; x < n; x++ )
{
for ( int y = 0; y < m; y++ )
{
System.out.print( table[x][y] + " " );
System.out.println( "col avg is " + avg1[x] );
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.