write a function that will reverse the numbers in a row?
so far done
public void fliprow(int r)
{
int temp = m[r][m[r].length-1];
int ct = 1;
for(int column = m[r].length; column >= 0; column--)
{
m[r][column] = m[r][ct];
m[r][ct] = temp;
temp = m[r][m[r].length-ct];
if(ct < m[r].length)
ct++;
else
ct = ct;
}
}

Recommended Answers

All 2 Replies

Member Avatar for ztini

ouch, that makes my head hurt.

How about something like this instead?

private int[][] array = new int[][] { 
		{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 0, 1} };
	
	public void println() {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[0].length; j++)
				System.out.print(array[i][j] + " ");
			System.out.println();
		}
		System.out.println();
	}
	
	public void flipRow(int row) {
		println();	
		for (int i = 0; i < array[row].length / 2; i++) {
			int temp = array[row][array[row].length - 1 - i];
			array[row][array[row].length - i - 1] = array[row][i];
			array[row][i] = temp;
		}
		println();		
	}
Member Avatar for ztini

Duplicate post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.