Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package com.metanit;
  2. import java.util.InputMismatchException;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void findMax(int[] array1, int n) {
  7.         int Max = array1[1];
  8.         for(int i = 1;i<array1.length; i = i+2) {
  9.             System.out.print(array1[i] + " ");
  10.             if (Max <= array1[i]) {
  11.                 Max = array1[i];
  12.             }
  13.         }
  14.         System.out.println();
  15.         System.out.print(Max);
  16.     }
  17.  
  18.     public static void main(String[] args) {
  19.         System.out.print("Введите размер массива ");
  20.         Scanner in = new Scanner(System.in);
  21.         int n =0 ;
  22.         try {
  23.          n = in.nextInt();}
  24.           catch (InputMismatchException e){
  25.                 System.out.println("Ошибка. Это не число.");
  26.             }
  27.         if (n < 0) {
  28.             System.out.println("Ошибка.Ваше число должно быть больше нуля");
  29.         }
  30.             int[] array = new int[n];
  31.  
  32.         for (int i = 0; i < n; i++)
  33.             array[i] = (int) ((Math.random() * 100)-50);
  34.         for (int i : array)
  35.             System.out.print(i + " ");
  36.         findMax(array, n);
  37.     } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement