how to do this?

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]+" ");
            }
        }
     }
  }









Related Tutorials/Questions & Answers:
how to do this?
How do you do data mining projects?
Advertisements
How to do url rewritting?
how to do this - JavaMail
how to do gui
How do you define a constant?
How do I upgrade mysql?
How do you sum a dictionary
How do i do the coding for 'leaving a comment' in java
How can I do it? .click();
How do I do this program? I'm new to Java programming...
how do i solve this problem?
how do i solve this question?
how to do actionsheet in iphone?-RV
How do you call a constructor for a parent class?
How do you pass a variable by value?
How do I decompile Java class files?
How do I initialize a byte array in Java?
How do I compare strings in Java?
how to do map in iphone?-RV
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 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 do I get started with Bootstrap
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 TO DO WEBSITE INTERFACE FOR JAVA MODULE
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I learn Spring Framework?
how do you parse by reference in java(with JGrasp)
How do I generate random number?
How do I study big data?
How do beginners learn about Java?
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I download urllib3 for python 2.7
How do I start learning MongoDB?
how do i begin a two dimensional array?
How do I learn Python data science?
How do I start a data mining company?
How do I get a job in AI field?
How can I do data science course?

Ads