TakeHome-11.docx - 1) import java.util.Scanner; public...

This preview shows page 1 - 4 out of 4 pages.

The preview shows page 3 - 4 out of 4 pages.
1)importjava.util.Scanner;publicclassDiagonal {publicstaticvoidmain(String[]args) {Scannerinput=newScanner(System.in);double[][]m=newdouble[4][4];System.out.println("Enter a 4 by 4 matrix row by row: ");for(inti= 0;i<m.length;i++) {for(intj= 0;j<m[0].length;j++) {m[i][j] =input.nextDouble();}}System.out.printf("Sum of elements in major diagonal is %.1f ",sumMajorDiagonal(m));}publicstaticdoublesumMajorDiagonal(double[][]m) {doublesum= 0;for(inti= 0;i<m.length;i++) {sum+=m[i][i];}returnsum;}}
2)importjava.util.Scanner;publicclassZeros {publicstaticvoidmain(String[]args) {Scannerinput=newScanner(System.in);int[][]m=newint[4][4];introwIndex= 0;intlargest= -1;for(inti= 0;i<m.length;i++) {introwCount= 0;for(intk= 0;k<m[i].length;k++) {m[i][k] = (int)(Math.random() * 2);
End of preview. Want to read all 4 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
NoProfessor
Tags
Return statement, Void type, Scanner input, rowcount, columnCount

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture