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



Home Answers Viewqa Java-Beginners Two Dimensional array program

Have Programming Question? Ask it here!
 
 
 


Timothy Ouko Omare
Two Dimensional array program
1 Answer(s)      3 years and 8 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
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
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
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
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
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
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
program of array
program of array  write a program that initializes an array with ten random integers and then prints four lines of output,containing:every element at an even index,every even element,all elements in reverse order,and only
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
program in array
program in array  print("code sample");write a program that initializes an array with ten random integers and then prints four lines of output...[]=new int[10]; System.out.println("Array of Random Numbers
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
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
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
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called
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 variable in a java program
array variable in a java program  How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has.... Initialize an array of objects. Pass a name from the command line & search for the name in the array of objects , if it is existing print the information
Compare two char array in java
Description: This tutorial demonstrate how to compare two character array are equal or not. The Arrays.equals(c1, c2) helps to compare it and return boolean value. Code: import java.util.Arrays
Reverse integer array program
Reverse integer array program  Been tasked with the following question: Write a method that accepts an integer array and returns a new array with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8
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
program to implement array of objects
program to implement array of objects  import java.io.*; import java.util.*; public class dataa { DataInputStream in=new DataInputStream(System.in); int i; int a[i]=int acid[5]; String name1[i]=new String[5
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
 

 

 

DMCA.com