Advertisement
Waliullah8328

Highest and Lowest Value (With Array)

Feb 2nd, 2021
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SmallestLargest {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         int n,i;
  9.         System.out.print("Enter How Many Number You Want To Insert : ");
  10.         n = input.nextInt();
  11.         int arr[] = new int [n];
  12.  
  13.         System.out.println("Enter Your "+n+ " Numbers");
  14.         for(i=0;i<n;i++)
  15.         {
  16.             arr[i]= input.nextInt();
  17.         }
  18.  
  19.         int max = arr[0];
  20.         for(i = 1; i < n; i++)
  21.         {
  22.             if(arr[i] > max)
  23.             {
  24.                 max = arr[i];
  25.             }
  26.         }
  27.         System.out.println("The Maximum value: "+max);
  28.  
  29.         int min = arr[0];
  30.         for(i = 1;i < n;i++)
  31.         {
  32.             if(arr[i] < min)
  33.             {
  34.                 min = arr[i];
  35.             }
  36.         }
  37.         System.out.println("The Minimum value: "+min);
  38.  
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement