Computer Science, asked by gemsking80, 3 months ago

Q2. Write a program to take user input into an array of size n and performed the following:
1. Display smallest number
2. Display largest number


class 10 icse​

Answers

Answered by negiabhishek236
1

Answer:

import java.util.Scanner; class LargeSmallSum { public static void main(String args[ ]) { int n; int max, min, sum = 0; int i, j; Scanner s = new Scanner(System.in); System.out.print(“Enter no. of elements you want in array:”); n = s.nextlnt(); int a[ ] = new int[n]; System.out.println(“Enter all the elements:”); for (i = 0; i < n; i+ +) { a[i] = s.nextlntO; } max = a[0]; min = a[0]; for(i = 0; i < n ; i + +) { if(a[i] > max) { max = a[i]; } if (a[i] < min) { min = a[i]; } } System.out.println(“Maximum Number is:”+max); System.out.println(“Smallest Number is:” +min); for(i = 0; i < n; i+ +) { sum = sum + a[i]; } System.out.println(“Sum of the Numbers is:” +sum); } }Read more on Sarthaks.com - https://www.sarthaks.com/837550/write-program-input-integer-elements-into-array-size-and-perform-the-following-operations

Similar questions