Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AboveTheMainDiagonal {
- public static void main(String[] args) {
- Scanner myScan=new Scanner(System.in);
- int n=Integer.parseInt(myScan.nextLine());
- long[][] matrix=new long[n][n];
- for (int row = 0; row < matrix.length; row++) {
- for (int col = 0; col < matrix[row].length; col++) {
- matrix[row][col]=(long) Math.pow(2,row+col);
- }
- }
- long sum=0;
- for (int row = 0; row < matrix.length-1; row++) {
- for (int col = row+1; col < matrix[row].length; col++) {
- sum+=matrix[row][col];
- }
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment