Answer to Question #262387 in Java | JSP | JSF for dee

Question #262387

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-07T10:12:31-0500

Source code

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n;
		System.out.print("Enter n: ");
		n=in.nextInt();
		int [][] arr = new int [n][n];
		
		for(int row=0;row<n;row++){
		    for(int column=0;column<n;column++){
		        arr[row][column]=(int) Math.pow(n + row, column);
		    }
		}
		System.out.println("The values of the array are: ");
		for(int row=0;row<n;row++){
		    for(int column=0;column<n;column++){
		        System.out.print(arr[row][column]+"\t");
		    }
		    System.out.println();
		}
	}
}

Output


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