Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package Labs;
  2. import java.util.Scanner;
  3. //9.1. Дан одномерный массив Xn. Найти максимальный элемент массива, попадающий в ин- тервал [А, В].
  4. public class Ol9_1 {
  5.     public static double[] InputArray() {
  6.         Scanner s = new Scanner(System.in);
  7.         System.out.print("n = ");
  8.         int n = s.nextInt();
  9.         double[] x = new double[n];
  10.         for (int i = 0; i < n; i++) {
  11.             System.out.print("№" + i + ": ");
  12.             x[i] = s.nextDouble();
  13.         }
  14.         return x;
  15.     }
  16.     static void Max(double[] x){
  17.         Scanner s = new Scanner(System.in);
  18.         int max = -1;
  19.         System.out.print("A = ");
  20.         int A = s.nextInt();
  21.         System.out.print("B = ");
  22.         int B = s.nextInt();
  23.         for (int i=0;i<x.length;i++){
  24.             if (x[i]>=A && x[i]<=B) {
  25.                 if (x[i] > max)
  26.                     max = i;
  27.             }
  28.         }
  29.         System.out.print("Max: #" + max + ", значение: " + x[max]);
  30.     }
  31.     public static void main(String[] args){
  32.         Max(InputArray());
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement