MiniMi2022

Above The Main Diagonal

Mar 4th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AboveTheMainDiagonal {
  4.     public static void main(String[] args) {
  5.         Scanner myScan=new Scanner(System.in);
  6.         int n=Integer.parseInt(myScan.nextLine());
  7.         long[][] matrix=new long[n][n];
  8.         for (int row = 0; row < matrix.length; row++) {
  9.             for (int col = 0; col < matrix[row].length; col++) {
  10.                 matrix[row][col]=(long) Math.pow(2,row+col);
  11.             }
  12.         }
  13.         long sum=0;
  14.         for (int row = 0; row < matrix.length-1; row++) {
  15.             for (int col = row+1; col < matrix[row].length; col++) {
  16.                 sum+=matrix[row][col];
  17.             }
  18.         }
  19.         System.out.println(sum);
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment