Computer Science, asked by singhranjankumar987, 7 months ago

write a program to accept 15 different numbers in a single dimensional array (SDA) display the greatest and smallest number of the array element. solution​

Answers

Answered by amritagurjar01
3

Answer:

Find Largest and Smallest Number in an Array Example

  This Java Example shows how to find largest and smallest number in an

  array.

*/

public class FindLargestSmallestNumber {

 

public static void main(String[] args) {

//array of 10 numbers

int numbers[] = new int[]{32,43,53,54,32,65,63,98,43,23};

//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);

}

}

 

/*

Output of this program would be

Largest Number is : 98

Smallest Number is : 23

*/

Answered by Oreki
1

import java.util.Arrays;

import java.util.Scanner;

public class LargestSmallest {

public static void main(String[ ] args) {

int[ ] array = new int[15];

System.out.println("Enter 15 numbers - ");

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

array[i] = new Scanner(System.in).nextInt( );

Arrays.sort(array);

System.out.printf("%nMinimum - %d%nMaximum - %d", array[0], array[15 - 1]);

}

}

Similar questions