Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that reverses the order of the elements in each row of the matrix. Print out the resulting matrix. import java.io . *

Write a program that reverses the order of the elements in each row of the matrix.
Print out the resulting matrix. import java.io.* ;
public class Ch67ex06_ReverseRow_4a_stu
{
static int[][] data ={{3,2,5},// ragged array, "data"
{1,4,4,8,13},
{9,1,0,2},
{0,2,6,3,-1,8},
{-1,-2,-3,4,5,45},
{56},
{0,1,2,3,4,5,6,7}};
private static void printArray()
{
PLN("");
for ( int row=0; row < data.length; row++)// process by rows
{
for ( int col=0; col < data[row].length-1; col++)// process each column of a row
P( data[row][col]+","); // scope is one line, not a block
PLN( data[row][data[row].length-1]);
}
}
public static void main ( String[] args )
{
printArray(); // print out the initial array
for ( int row=0; row < data.length; row++)// process all rows
{
int endIdx = data[row].length; // determine ending column number
for ( int col=0; col < endIdx/2 ; col++)//# use half the row; even/odd! #//
{
//---- insert code here ----//
//# standard swap #//
//# put end col into start col #//
//# be careful with 'off by one' #//
}//# half cols because of swapping #//
}
printArray(); // print out the row-reversed array
}
public static void P(Object x){System.out.print(x);}// Shorthand System.out.print()
public static void PLN(Object x){System.out.println(x);}// Shorthand System.out.println()
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

-3 [6 + 2(4 8)] Perform the indicated operations by hand.

Answered: 1 week ago

Question

b. Where did they come from?

Answered: 1 week ago