Computer Science, asked by gourav4338, 1 year ago

write a program in Java to input 10 numbers in an array and print the maximum and minimum numbers present in the array?​

Answers

Answered by gurukulamdivya
35

Answer:

public class FindLargestSmallestNumber

{

public static void main(String[] args)

{

  Scanner input = new Scanner(system.in);

 //array of 10 numbers

 int numbers[10] ;

               System.out.println("Enter 10 number in an Array");

               for (i=0;i<10;1++)

               {

                  numbers[i]=input.nextInt();

               }

 //assign first element of an array to largest and smallest

 int smallest = numbers[0];

 int largetst = numbers[0];

 for(int i=1; i< numbers.length; i++)

 {

  if(numbers[i] > largetst)

   largetst = numbers[i];

  else if (numbers[i] < smallest)

   smallest = numbers[i];

 }

 System.out.println("Largest Number is : " + largetst);

 System.out.println("Smallest Number is : " + smallest);

}

}

Answered by KshitijSahdev
14

import java.util.Scanner;

public class big_small

{

   public static void main(String args[])

   {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter your 10 numbers");

       int a[]=new int[10];

       for (int i=0;i<10;i++)

       {

           a[i]=in.nextInt();

       }

       int s= a[0];

       int l= a[0];

       for(int j=0;j<10;j++)

       {

           if(a[j] > l)

               l = a[j];

           else if (a[j] < s)

               s = a[j];

       }

       System.out.println("Largest Number is : " + l);

       System.out.println("Smallest Number is : " + s);

       

   }

}

Similar questions