Answer to Question #258060 in Java | JSP | JSF for gunna24

Question #258060
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. 5 4 3 2 1 10 8 6 4 2 15 12 9 6 3 20 16 12 8 4 25 20 15 10 5 Sample Run1 Enter a number (N): 5 Output1: 5 4 3 2 1 10 8 6 4 2 15 12 9 6 3 20 16 12 8 4 25 20 15 10 5 Sample Run2 Enter a number (N): 3 Output2: 3 2 1 6 4 2 9 6 3
1
Expert's answer
2021-10-28T12:37:32-0400
import java.util.Scanner;
public class Main
{
 public static void main(String[] args) {
 Scanner in=new Scanner(System.in);
 System.out.print("Enter a number (N): ");
 int n=in.nextInt();
 int num=1;
 for(int i=n;i>=1;i--)
 {
     for(int j=n;j>=1;j--)
     {
     System.out.print((j*num)+"\t");
     }
     System.out.println();
     num++;
 }
 }
}

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