Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.metanit;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- public class Main {
- public static void findMax(int[] array1, int n) {
- int Max = array1[1];
- for(int i = 1;i<array1.length; i = i+2) {
- System.out.print(array1[i] + " ");
- if (Max <= array1[i]) {
- Max = array1[i];
- }
- }
- System.out.println();
- System.out.print(Max);
- }
- public static void main(String[] args) {
- System.out.print("Введите размер массива ");
- Scanner in = new Scanner(System.in);
- int n =0 ;
- try {
- n = in.nextInt();}
- catch (InputMismatchException e){
- System.out.println("Ошибка. Это не число.");
- }
- if (n < 0) {
- System.out.println("Ошибка.Ваше число должно быть больше нуля");
- }
- int[] array = new int[n];
- for (int i = 0; i < n; i++)
- array[i] = (int) ((Math.random() * 100)-50);
- for (int i : array)
- System.out.print(i + " ");
- findMax(array, n);
- } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement