Answer to Question #257544 in Java | JSP | JSF for NUCHO

Question #257544

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-10-28T01:24:14-0400
import java.util.*;
class Main {
    public static void main(String[] args)
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter the size of the array: ");
        int n=input.nextInt();
        double[][] arr = { { 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 i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                System.out.println("arr[" + i + "][" + j + "] = "
                                   + arr[i][j]);
    }
}

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