Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package package1;
- import java.util.Scanner;
- public class class1 {
- public static final int counter = 10;
- public static final int sides = 10;
- public static void readFigure (int[][] figure) {
- Scanner sc = new Scanner(System.in);
- int st = 0;
- int count, side;
- do {
- System.out.println("Въведете брой на многоъгълници (от 2 до 10): ");
- count = sc.nextInt();
- } while (count <= 1 || count > 10);
- do {
- System.out.println("Въведете брой на страни (от 3 до 10): ");
- side = sc.nextInt();
- } while (side <= 2 || side > 10);
- for (int i = 0; i < count; i++) {
- System.out.println("Въведете страните на фигура " + (i+1) + ": ");
- for (int j = 0; j < side; j++) {
- do {
- System.out.println("Въведете страна номер " + (j + 1) + " : ");
- st = sc.nextInt();
- if (st > 0) {
- figure[i][j] = st;
- } else {
- System.out.println("Въведената стойност е невалидна! Опитайте отново!");
- }
- } while (st <= 0);
- }
- }
- if(!(sc.hasNextLine()))
- sc.close();
- }
- public static void sumFigure (int[][] figure) {
- int sum[] = new int [counter];
- for (int i = 0; i < counter; i++) {
- for (int j = 0; j < sides; j++) {
- sum[i] += figure[i][j];
- }
- } int max = 0, maxnumber = 0;
- for (int i = 0; i < counter; i++) {
- if(max < sum[i]) {
- max = sum[i];
- maxnumber = i;
- }
- }
- System.out.println("Фигура " + (maxnumber + 1) +" е с най-голям параметър: " + max);
- }
- public static void main(String[] args) {
- int[][] figures = new int[counter][sides];
- readFigure(figures);
- sumFigure(figures);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement