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

Question #256431

Given a number N, create a 2D arrays with n rows and n columns. Now inspect the matrix pattern below and come up with a formula to populate the array for any give NXN matrix.


1
Expert's answer
2021-10-27T03:49:09-0400
import java.util.*;


public class Main
{
	public static void main(String[] args) {
	 Scanner scan = new Scanner(System.in);
 System.out.print("Enter a Number N: ");
 int n = scan.nextInt();
 for(int i = 0; i<n; i++)
 {
 int first_row = (n*(i+1));
 for(int j = 0; j< n; j++)
 {
 int value = first_row;
 


 if(value>9)
 {
 
 System.out.print(value+" ");
 }
 else{
 System.out.print(value+" ");
 }


 
first_row = first_row -(i+1);
 }
 System.out.println();
 }
	}
}

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