Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main
- {
- public static void main(String[] args)
- {
- final double MAX = 20.0;
- Scanner input = new Scanner(System.in);
- int n = input.nextInt();
- double[][] array = new double[n][n];
- for (int i = 0; i < n; i++){
- for (int j = 0; j < n; j++){
- array[i][j] = Math.random() * 10;
- System.out.print(array[i][j] + " ");
- }
- System.out.println();
- }
- double diagSummary = 0;
- double result = 0;
- int isUpper = 0;
- for (int i = 0; i < n; i++){
- diagSummary += array[i][i];
- if (diagSummary > MAX) isUpper = 1;
- }
- int index = 1;
- for (int j = 0; j < n - 1; j++){
- int k = index;
- do{
- switch(isUpper){
- case 0: result += array[k][j];
- break;
- case 1: result += array[j][k];
- break;
- }
- k++;
- }while (k < n);
- index++;
- }
- System.out.println("result: " + result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement