how to do this?

Ads
 

how to do this?

  1. Given any integer 2D array, design then implement a Java program that will add to each element in the array the corresponding column number and the corresponding row number. Then, it prints the array before and after modification. For example, if the program fed with following 2D array: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    The output should be as follows:
    

original 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

new 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6

View Answers

April 19, 2012 at 1:24 PM

class TwoDArray{
    public static void main(String[]args){
    int[][] A = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
    int[][] B = new int[3][5];

    System.out.println("Original Array: ");
        for(int i=0 ; i < A.length ; i++){
            System.out.println();
            for(int j=0 ; j < A[i].length ; j++){
                System.out.print(A[i][j]+" ");
            }
        }
    System.out.println();
    System.out.println();
        for (int i=0 ; i < B.length ; i++){
            for  (int j=0 ; j < B[i].length ; j++){
                B[i][j] = i+j;
            }
        }
        System.out.println("New Array: ");
        for(int i=0 ; i < B.length ; i++){
            System.out.println();
            for(int j=0 ; j < B[i].length ; j++){
                System.out.print(B[i][j]+" ");
            }
        }
     }
  }

Ads









Related Tutorials/Questions & Answers:
how to do this?
How to do url rewritting?
Advertisements
how to do gui
How do I upgrade mysql?
How can I do it? .click();
How do i do the coding for 'leaving a comment' in java
how do i solve this problem?
how do i solve this question?
how to do actionsheet in iphone?-RV
how to do map in iphone?-RV
How do I decompile Java class files?
How do I initialize a byte array in Java?
How do I compare strings in Java?
How do I do this program? I'm new to Java programming...
How do we create session factory in hibernate?
How do I compile the registration form?
How do we create custom component
how to do abstraction for insurance policy being issued...
How to do Static Resources Configuration in Spring MVC?
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
How do you add a numerical value to a regex
How do SEL and @selector work in iphone sdk?
How do I get started with Bootstrap
How do I get started with Bootstrap
HOW TO DO WEBSITE INTERFACE FOR JAVA MODULE
How do I generate random number?
How do I study big data?
How do beginners learn about Java?

Ads