Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
4.1k views
in JECRC University B.Tech(CSE-V Sem) Java Programming Lab by Goeduhub's Expert (5.8k points)
Java program to find the largest and smallest number in an array

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 360/- || For International Students- $9.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence || Labeled as Highest Rated Course by Udemy

Apply Coupon

2.

Complete Machine Learning & Data Science with Python| ML A-Z Apply Coupon

3.

Complete Python Programming from scratch | Python Projects Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
 
Best answer

Program Code

import java.util.*;

public class MinMax

{

   public static void main(String[] args)

   {

   Scanner sc=new Scanner(System.in);

    int arr[]=new int[6]; //declaring array

    System.out.print("Enter 6 array elements: ");

    for(int i=0;i<arr.length;i++)

           arr[i]=sc.nextInt(); //taking input from user

    System.out.println("Entered Array: ");

    for(int i=0;i<arr.length;i++)

           System.out.print(arr[i]+ " ");

    int min=arr[0],max=arr[0];

    for(int i=0;i<arr.length;i++)

    {

       if(min>arr[i])

           min=arr[i];

       if(max<arr[i])

          max=arr[i];

     }

     System.out.println("\nMaximum is : "+max);

     System.out.println("Minimum is : "+min);

     }

}

Output

Enter 6 array elements: 1

7

290

-249

0

23

Entered Array: 1 7 290 -249 0 23

Maximum is : 290

Minimum is : -249


For more JU V Sem Java Lab Experiments Click here


3.3k questions

7.1k answers

394 comments

4.6k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...