Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners reverse two dimensional arrays in java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


steven ablonda
reverse two dimensional arrays in java
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


reverse array elements in two dimensional array such that the last element becomes the first


Advertisement
View Answers

November 17, 2010 at 2:42 PM


Hi Friend,

Try the following code:

import java.util.*;

public class TDArray { public static void reverse(int[][] arr){

 int rows = arr.length;
    int cols = arr[0].length;
    int array[][]=new int[rows][cols];
    for(int i = rows-1; i >= 0; i--) {
        for(int j = cols-1; j >= 0; j--) {
            array[rows-1-i][cols-1-j] = arr[i][j];
        }
    }
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < cols; j++) {
            System.out.print(array[i][j]+" ");
            }
     }
}

public static void main(String[] args) throws Exception {
    int rows, cols;
    int[][] arr;
    Scanner input = new Scanner(System.in);
    System.out.print("Enter number of rows greater than 20: ");
    rows = input.nextInt();
    System.out.print("Enter number of columns greater than 20: ");
    cols = input.nextInt();
    arr = new int[rows][cols];
    System.out.println("Enter elements of Array");
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            arr[i][j] = input.nextInt();
        }
    }
    System.out.println("Array is: ");
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
        System.out.print(arr[i][j]+" ");
        }
    }
    System.out.println();
    reverse(arr);

        }

}

Thanks



Related Tutorials/Questions & Answers:
reverse two dimensional arrays in java
reverse two dimensional arrays in java  reverse array elements in two dimensional array such that the last element becomes the first
Two-dimensional arrays
Two-Dimensional Arrays       Two-dimensional arrays are defined as "an array of arrays"... of arrays of  ints". Such an array is said to be a two-dimensional array. 
Advertisements
reverse arrays in java
reverse arrays in java  how do i make a code that can be used to reverse the elements of an array in two dimension such that the last element of an array becomes the first element of the array and the first element of an array
reverse arrays in java
reverse arrays in java  how do i write a program in array of size n*m where both n and m are greater than 20 such that the 1st element of an array becomes the last and vice verse
two dimensional - Java Beginners
two dimensional  write a program to create a 3*3 array and print the sum of all the numbers stored in it.  Hi Friend, Try the following code: import java.io.*; import java.util.*; public class matrix
Two- Dimensional Array - Java Beginners
Two- Dimensional Array  I am new in java programming. I am creating a two-dimensional array. This is my code ** class BinaryNumbers { public static void main(String[] args) { //create a two-dimensional array int ROWS = 21
intersection of two java arrays
intersection of two java arrays  I am trying to figure out how to compare two arrays and get the intersection and put this into a third array of the correct size. I know how to copy the two arrays into the third array but am
How to concatenate two arrays in Java?
How to concatenate two arrays in Java?  How to concatenate two arrays in Java
Two dimensional array in java
Two dimensional array in java. In this section you will learn about two-dimensional array in java with an example. As we know that array is a collection... dimensional array is defined as an "array of array". In java the element
php two dimensional array
php two dimensional array  php two dimensional array example
two dimensional array
two dimensional array  how tow dimensional array works.How those loopes get incremented .and how every time the value of k changes
Multi-dimensional arrays
; The Java programming language does not really support multi-dimensional arrays. It does, however, supports an array of arrays. In Java, a two-dimensional array... Multi-dimensional arrays      
Two Dimensional array program
Two Dimensional array program  consider a two dimensional array of size mn where both mn are greater than 20.derive a function that can be used to elements of the array such that the last element become the first one
Compare two Byte Arrays?
Compare two Byte Arrays?  Compare two Byte Arrays
Two Dimensional Array Program
Two Dimensional Array Program    ... will learn how to display arrange form of two dimensional array program... a integer for array declaration Two dimensional array program. We are going
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop...; program . In this session we will teach how to use of a two dimensional array... are going to make two dimensional array having three row and three columns. 
how do i begin a two dimensional array?
how do i begin a two dimensional array?  I'm new to java programming and need to create a two dimensional array that enters exactly what is entered in the first dimension and then the first non-white space character of what
combine two arrays in php
combine two arrays in php  combine two arrays in php   $newArray = array_combine($diff, $pages_name['data']); foreach ($newArray as $data) { var_dump($data); exit('zzzzz'); echo $data . '<br>
Square Elements of Two Dimensional Array
Square Elements of Two Dimensional Array        This is a simple java program for implementing the two dimensional array program and its square. This session provide you
Two Dimensional Array Program Using Nested For Loop
Two Dimensional Array Program Using Nested For Loop ... of Java. In this lesson we will learn how to display arrange form of two...;. We are going to make a integer for array declaration Two dimensional array
Need coding help - two dimensional matrix and it returns back a boolean.
Need coding help - two dimensional matrix and it returns back a boolean.  I need to write a code method that accepts a two dimensional integer arrays as the argument and returns true if the array or matrix is left or right
Merging Two Arrays Of Different Lengths
Merging Two Arrays Of Different Lengths  I have two arrays of different lengths and wants to have merged values into third. The only condition is, I want unique values in it(third array). Thanks In Advance
Arrays in java
Arrays in java  what is param array in java
Declare string array in Java (one and two dimensional)
Declare string array in Java (one and two dimensional... program also teaches you how to declare two dimensional array in Java... dimensional array and two dimensional as well. 1. String arr[] = new String
Java with Arrays
Java with Arrays  I was given the assignment to create two parallel arrays; both of size 50 (declares 50 as a constant) One is an array of strings... and store it in the arrays. The input for the problem should be provided in a text
Arrays
Arrays  Write a program in java(BlueJ) to store the numbers in single dimensional array(S.D.A)into another S.D.A in reverse order of the location
Reverse
Reverse  How to reverse two digits in javaprogramming
Reverse
Reverse  How to reverse two digits in javaprogramming
java arrays
java arrays  i need a java program to store student details like id,name,addr,marks,average,total..using arrays..input data using scanner class and by using class, object and constructor
java arrays
java arrays  can i know how can we intilize the three dimentional arrays in java? and how can we assign thae values to that array
Introduction to java arrays
-dimensional and two-dimensional arrays. To store data in more dimensions a multi... multi-dimensional arrays. It does, however, supports an array of arrays. In Java... operator. Two-dimensional arrays Two-dimensional arrays are defined as "
Advertisements
 

 

 

DMCA.com