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



Home Answers Viewqa Java-Beginners Two Dimensional array program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Timothy Ouko Omare
Two Dimensional array program
1 Answer(s)      4 years and 2 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


Advertisement
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 Tutorials/Questions & Answers:
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. 
Advertisements
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
two dimensional array  how tow dimensional array works.How those loopes get incremented .and how every time the value of k changes
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
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
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
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
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
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
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
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
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 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
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
Declare string array in Java (one and two dimensional)
program also teaches you how to declare two dimensional array in Java... Declare string array in Java (one and two dimensional... dimensional array and two dimensional as well. 1. String arr[] = new String
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 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
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
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
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
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
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      
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
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
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
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
 

 

 

DMCA.com