Answer to Question #259728 in Java | JSP | JSF for Amadix

Question #259728

 Write a java program that accepts a given n, then create a 2D array with n rows and n columns. Then for each cell the value should be n+row to the power column. For example if we talk of n=5, then array[0][0] =(5+0)0 = 1. Print out all the values in the array created.



1
Expert's answer
2021-11-01T18:49:44-0400
import java.util.*;
class Main {
    public static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        System.out.println("Input the size of the array: ");
        int n=scan.nextInt();
        double[][] array = { { Math.pow((n+0),0), Math.pow((n+0),1),Math.pow((n+0),2),Math.pow((n+0),3),Math.pow((n+0),4) },
        {Math.pow((n+1),0), Math.pow((n+1),1),Math.pow((n+1),2),Math.pow((n+1),3),Math.pow((n+1),4) },
        {Math.pow((n+2),0),Math.pow((n+2),1),Math.pow((n+2),2),Math.pow((n+2),3),Math.pow((n+2),4)},
        {Math.pow((n+3),0),Math.pow((n+3),1),Math.pow((n+3),2),Math.pow((n+3),3),Math.pow((n+3),4)},
        {Math.pow((n+4),0),Math.pow((n+4),1),Math.pow((n+4),2),Math.pow((n+4),3),Math.pow((n+4),4)}};
  
        for (int x = 0; x < n; x++)
            for (int y = 0; y < n; y++)
                System.out.println("arr[" + x + "][" + y + "] = "
                                   + array[x][y]);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS