Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Labs;
- import java.util.Scanner;
- //9.1. Дан одномерный массив Xn. Найти максимальный элемент массива, попадающий в ин- тервал [А, В].
- public class Ol9_1 {
- public static double[] InputArray() {
- Scanner s = new Scanner(System.in);
- System.out.print("n = ");
- int n = s.nextInt();
- double[] x = new double[n];
- for (int i = 0; i < n; i++) {
- System.out.print("№" + i + ": ");
- x[i] = s.nextDouble();
- }
- return x;
- }
- static void Max(double[] x){
- Scanner s = new Scanner(System.in);
- int max = -1;
- System.out.print("A = ");
- int A = s.nextInt();
- System.out.print("B = ");
- int B = s.nextInt();
- for (int i=0;i<x.length;i++){
- if (x[i]>=A && x[i]<=B) {
- if (x[i] > max)
- max = i;
- }
- }
- System.out.print("Max: #" + max + ", значение: " + x[max]);
- }
- public static void main(String[] args){
- Max(InputArray());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement