Page 84 - CITS - CSA - TP (Volume 2) - Hindi
P. 84
कं ूटर सॉ वेयर ए ीके शन - CITS
• अंत म , यह ऐरे एलीम ट का योग ि ंट करता है।
• scanner.close() कथन िस म संसाधनों को रलीज़ करने के िलए ै नर को बंद कर देता है।
यह ो ाम उपयोगकता को ऐरे एलीम ट को गितशील प से इनपुट करने और तदनुसार योग की गणना करने की अनुमित देता है।
टा 2: िकसी ऐरे म अिधकतम एलीम ट ढूँढना
public class MaxElement {
public static void main(String[] args) {
// Declare and initialize an array
int[] numbers = {10, 5, 20, 8, 15};
System.out.print(“Element in the array are: “);
// Assume the first element is the maximum
int max = numbers[0];
// Iterate through the array to find the maximum element
for (int i = 1; i < numbers.length; i++) {
System.out.print(numbers[i]+” “) ;
if (numbers[i] > max) {
max = numbers[i];
}
}
System.out.println();
// Print the maximum element
System.out.println(“Maximum element in the array: “ + max);
}
}
आउटपुट:
70
CITS : IT & ITES - कं ूटर सॉ वेयर ए ीके शन - अ ास 93

