Chrome File Edit View History Bookmarks People Window Help 88% Wed Apr 12 9:48:5
ID: 3816147 • Letter: C
Question
Chrome File Edit View History Bookmarks People Window Help 88% Wed Apr 12 9:48:57 AM x C chegg study I Guided solutior nbox jking199@students. A11.pd 5 X ksuweb.kennesaw.edu hhaddad/Spring2017/CS1301/A11.pd Apps k D cs 130 LIowlLink-Online Ca PlayStation Vue D Y2U40DAXNDgyZS... CompTIA A+ Certifi Program YouTube home M Inbox king 199@s A11.pdf name it tRowcolumn). The program randomly fills in 0s and 1s into a 4-by-4 matrix, prints the filled matrix, and then finds the first row and first column with the most 1s. Notice there could be other rows and columns the most ones. We just need to find the first row and first column with the most 1s. Format your output following the given sample run. Design the main method of your program such that it allows the user to re-run the program in the same session (run). Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable. Program E3110 points Design and implement a a program for programming e 8.27, page 315 name it columnsorting) as described in the problem statement. Write method sortColumns0 as specified (you may change the element type to integer). Notice that this method returns a new array the original array remains unchanged. To test this method, the main method of your program prompts the user to enter a two- dimensional array and displays the original array followed by the column-sorted array as shown in the sample run. Design the main method of your program such that it allows the user to re-run the rogram in the same on (run). Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable Program P4 (10 points Design and implement a Java program for programming exercise 8.29, page 316 icalArrays) as described in the problem statement. Write method equals0 as specified. To name test this method, the main method of your program prompts the user to enter 2 two-dimensional arrays of integers and displays whether the two arrays are identical or not. Follow the given sample run to format your outputs. Design the main method of your program such that it allows the user to re-run the program with different inputs (i e., use a loop) Document your code, and organize and space the outputs property. Use escape characters and formatting objects when applicable. Submission Instructions 1. Assignment due date: Wednesday 4112/2017 at the beginning of the lab session 2. Email your code (only the java files) to the instructor du) and the grader (paggarwa@students kennesaw.edu) before the start of the lab session you attend. Re-submission for any reason is considered late submission (see course syllabus Assignment Grading Policy). Page 1 of 2Explanation / Answer
public class Ex_27 {
public static void main(String[] args) {
double[][] p = new double[3][3];
Scanner
input = new Scanner(System.in);
System.out.println("Enter the 3 by 3 matrix row by row: ");
for (int j= 0; j < p.length; j++)
for (int k = 0; k < p[j].length; k++)
p[j][k] = input.nextDouble();
double[][] sorted = sortColumns(p);
displayMatrix(sorted);
}
public static double[][] sortColumns(double[][] p) {
// create copy array
double[][] sorted = new double[p.length][p[0].length];
for (int j = 0; j < p.length; j++) {
for (int k = 0; k < p[j].length; k++) {
sorted[j][k] = p[j][k];
}
}
for (int k = 0; k < sorted[0].length; k++) {
for (int j = 0; j < sorted.length - 1; j++) {
double currentMin = sorted[j][k];
int minIndex = j;
for (int row = j + 1; row < sorted.length; row++) {
if (currentMin > sorted[row][k]) {
currentMin = sorted[row][k];
minIndex = row;
}
}
if (minIndex != j) {
sorted[minIndex][k] = sorted[j][k];
sorted[j][k] = currentMin;
}
}
}
return sorted;
}
public static void displayMatrix(double[][] p) {
for (int j = 0; j < p.length; j++) {
for (int k = 0; k < p[j].length; k++) {
System.out.printf("%2.3f ", p[j][k]);
}
System.out.println("");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.