Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package package1;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class class1 {
  7.  
  8.     public static final int counter = 10;
  9.     public static final int sides = 10;
  10.      public static void readFigure (int[][] figure) {
  11.  
  12.             Scanner sc = new Scanner(System.in);
  13.             int st = 0;
  14.             int count, side;
  15.             do {
  16.                 System.out.println("Въведете брой на многоъгълници (от 2 до 10): ");
  17.                 count = sc.nextInt();
  18.             } while (count <= 1 || count > 10);
  19.             do {
  20.                 System.out.println("Въведете брой на страни (от 3 до 10): ");
  21.                 side = sc.nextInt();
  22.             } while (side <= 2 || side > 10);
  23.            
  24.                 for (int i = 0; i < count; i++) {
  25.                     System.out.println("Въведете страните на фигура " + (i+1) + ": ");
  26.                     for (int j = 0; j < side; j++) {
  27.                         do {
  28.                             System.out.println("Въведете страна номер " + (j + 1) + " : ");
  29.                             st = sc.nextInt();
  30.                             if (st > 0) {
  31.                                 figure[i][j] = st;
  32.                             } else {
  33.                                 System.out.println("Въведената стойност е невалидна! Опитайте отново!");
  34.                             }
  35.                         } while (st <= 0);
  36.                     }
  37.                 }
  38.                   if(!(sc.hasNextLine()))
  39.                        sc.close();
  40.  
  41.         }
  42.         public static void sumFigure (int[][] figure) {
  43.             int sum[] = new int [counter];
  44.             for (int i = 0; i < counter; i++) {
  45.                 for (int j = 0; j < sides; j++) {
  46.                     sum[i] += figure[i][j];
  47.                 }
  48.             }   int max = 0, maxnumber = 0;
  49.             for (int i = 0; i < counter; i++) {
  50.                if(max < sum[i]) {
  51.                    max = sum[i];
  52.                    maxnumber = i;
  53.                }
  54.            
  55.             }
  56.             System.out.println("Фигура " + (maxnumber + 1) +" е с най-голям параметър: " + max);
  57.  
  58.         }
  59.    
  60.     public static void main(String[] args) {
  61.    
  62.         int[][] figures = new int[counter][sides];
  63.            
  64.             readFigure(figures);
  65.             sumFigure(figures);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement