Home Answers Viewqa Java-Beginners Two Dimensional array program

 
 


Timothy Ouko Omare
Two Dimensional array program
1 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners

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 and the first become the last.let the program output elements of the first array and the elements of the new array

View Answers

November 15, 2010 at 10:55 AM


Hi Friend,

You can try the following code:

import java.util.*;

public class TDArray {
    public static void find(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();
        find(arr);

            }
}

Thanks









Related Pages:
Two Dimensional array program
Two Dimensional array program  consider a two dimensional array... to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array
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. 
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    
php two dimensional array
php two dimensional array  php two dimensional array example
Two dimensional array in java
Two dimensional array in java. In this section you will learn about two.... int arr[][]; Here arr is a two-dimensional array of type int. To create an array... : A simple program of two dimension array. public class Twodarray
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
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 Program Using Nested For Loop
Two Dimensional Array Program Using Nested For Loop ... dimensional array program. Firstly, we have to define class "TwoDimensional ". We are going to make a integer for array declaration Two dimensional array
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 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. ... in each of those arrays. To process a two-dimensional array, we use nested
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes
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
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
Dividing Element of Two Dimensional Array
;ArrayDivideMatrix". Here you will learn how to use two matrix array for developing Java program.  The java two dimensional array program is operate the two... Dividing  Element of Two Dimensional Array
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
Three Dimensional Array program
Three Dimensional Array program   ... will learn how to use three dimensional array. Firstly, we have to define class... are going to make three dimensional array having multi rows and columns. By using
one dimensional array using java
one dimensional array using java  design and implement a java program that will read a file containing numbers and compute the following statistics: the range(low,high) the average and the median
Array in Java
. Different types of array used in Java are One-dimensional, Two-dimensional and multi...[] = {50,60,70,80,90}; Two-dimensional arrays: Two-dimensional arrays... an array in a program: Declaration of an Array Construction
Multi-dimensional arrays
that supports it, the element of the two-dimensional array x is denoted by x[i,j]. .... It does, however, supports an array of arrays. In Java, a two-dimensional array...; So far we have studied about the one-dimensional and two
A single dimensional array is called
A single dimensional array is called  What is a single dimensional array called?   A single dimensional array is called LIST
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
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble... cannot figure out how i can declare a two dimensional array without knowing how... many words he/she types without using an array list.   Thank you. I
Changing the value of Array in Java
;    This is very simple of one dimensional array program. In this tutorial you will learn how to change array values. The one dimensional... dimensional array program. In  this program firstly we are going to define
Declare string array in Java (one and two dimensional)
Declare string array in Java (one and two dimensional... dimensional array and two dimensional as well. 1. String arr[] = new String... and initialize two dimensional array String dim2[][] = { {"mahendra
program
Seventh Day of Week is Sunday Note: Use two dimensional array of String...program  Write a program to print details of a week for a particular day using array of objects Integer and String. OUTPUT: First Day of Week
Multidimensional Array Java
to store it in an array. We use mostly two types of arrays that is simple array and multi dimensional array.   In the example given below we have used two dimensional array. A two dimensional array can be thought as a grid
The Array Palindrome Number in Java
. In this section you will read how to uses palindrome one dimensional array program. The array palindrome number arrange the array number. This session... to make one dimensional program. For completion the example firstly we have define
Arrays -- Multi-dimensional
the element in that row/array. Visualizing two-dimensional arrays Assume we...] | | | +-----+-----+-----+-----+ +-----+ In Java two-dimensional arrays are implemented is a one-dimensional array... this. These examples all use two-dimensional arrays, but the same syntax and coding can
Multiplication of two Matrix
to declare two multidimensional array of type integer. Here in this program use two.... The Java two dimensional array  program is operate to the two matrix number...;    This is a simple Java multidimensional array program
Matrix multiplication in java
multiplication of two matrices. In java this is a simple program to multiply two matrices, we have to take two-dimensional array and the result should be saved in third two-dimensional array. Here we are going to develop a Java code for matrices
Dividing of two Matrix in Java
;Here you will learn how to use two matrix array for developing Java program.  The java two dimensional array program is operate the two matrix. Now we... to divided both matrix. This program using the two for loop. So the output
Array
Array  Write a program to store the population of 8 countries. i) Define two arrays to store the names of the countries and their populationââ?¬â?¢s numbers. ii) Write a loop that uses these arrays to print each countryââ?¬â?¢s
two dimansional array - Java Beginners
two dimansional array  Modify the following program so that it computes and prints the tables of powers from 1 to 15.( 1 to 15 to the power 1, Squared, and Cubed: like below) it should look like 1 1 1 2 4 8 3 9 27 and so
Multiplication of two Matrix
program that will multiply two matrix. Two dimensional array represents the matrix.  Now, make this program, you have to declare two multidimensional array of type integer. Program uses two for loops to get number of rows and columns
C Array of String
and handled like a 2d(two dimensional) arrays. You can see in the given example that we have declare a 2 dimensional character array consisting of three 'rows' and twelve... C Array of String      
To find first two maximum numbers in an array
To find first two maximum numbers in an array  Java program to find first two maximum numbers in an array,using single loop without sorting array
Java Program
Java Program  I want to Write a program in JAVA to display to create a class called MATRIX using a two-dimensional array of integers. Perform the addition and subtraction of two matrices. Help me
Display tow dimensional array using one for loop in java
Display tow dimensional array using one for loop in java  Display tow dimensional array using one for loop in java
Display tow dimensional array by matrix form using one for loop in java
Display tow dimensional array by matrix form using one for loop in java  Display tow dimensional array by matrix form using one for loop in java
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
Array Strings
Array Strings  String auto[]=new String[]{"Length: ","Breadth: ","Height: "}; in the above code i can easily input values into my string auto which is a single dimensional array. How do you do this with a two dimensional array
Sum of two Matrix
to this. In this program we are going to calculate the sum of two matrix. To make this program, we need to declare two dimensional array of type integer. Firstly... Sum of  two Matrix      
Java Array - Java Beginners
Java Array  Q4-Write a program to exchange the nondiognal elements of a two dimensional array A of size NxN without using any other array ie. each a[i][j]with a[j][i] where i is not equal j?   Hi Friend, Please try
array program
array program  write a java program which will take 10 elements as command line arguments and count how many times 3 occurs in array
comparing arraylist of an multi dimensional arraylist
comparing arraylist of an multi dimensional arraylist  can anyone help me in solving the following issue: actually i have an arraylist called dany... araylist.if we find the content of the two arraylist similar then it shuld be stored
Netbeans program
Netbeans program  I need to write a program that does the following... The TicTacToe class contains a 3x3 two-dimensional array of integers... playerMove that accepts two integers as parameters, the first is the player (1
plz try to clear my doubt for shuffling multi-dimensional array
plz try to clear my doubt for shuffling multi-dimensional array  hi... want to shuffle the ful entire multi-simensional array means wat v want to do... final int size = 5; private int[][] array = new int[size][size]; private
Creation Time Comparison of Multi Dimensional Array- Java Tutorials
Creation Time Comparison of Multi Dimensional Array In this section, we will compare the creation time between the different size/dimension of array.  As you know that multidimensional array is the array of arrays. Practically
Netbeans Array help
]); } } } This is what I am trying to get my program to due- using a two-dimensional array to tally the actual combinations of rolls. A roll of 2 and 7 would...Netbeans Array help  Ok here is my code- * * To change this template

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.