Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
837 B
5
Indexable
Never
import java.util.*;

public class ArrayAnalyzerB {

   private int[] arr;
   
   public ArrayAnalyzerB(int[] arr) {
      this.arr = arr;
   }
   
   public int countInRange() {
      Scanner scanner = new Scanner(System.in);
      System.out.print("Enter minimum value: ");
      int minVal = scanner.nextInt();
      System.out.print("Enter maximum value: ");
      int maxVal = scanner.nextInt();
      
      int count = 0;
      for (int num : arr) {
         if (minVal <= num && num < maxVal) {
            count++;
         }
      }
      return count;
   }
    
   public static void main(String[] args) {
      int[] array = {14, 1, 22, 7, -43, 5};
      ArrayAnalyzerB analyzer = new ArrayAnalyzerB(array);
      int result = analyzer.countInRange();
      System.out.println("Count of Elements in Range: " + result);
   }
}
Leave a Comment