Computer Applications
Define a class to declare an array of size 20 of double datatype, accept the elements into the array and perform the following:
Calculate and print the sum of all the elements.
Calculate and print the highest value of the array.
Java
Java Arrays
8 Likes
Answer
import java.util.Scanner;
public class KboatSDASumMax
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
double arr[] = new double[20];
System.out.println("Enter 20 numbers:");
for (int i = 0; i < 20; i++) {
arr[i] = in.nextDouble();
}
double max = arr[0], sum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] > max)
max = arr[i];
sum += arr[i];
}
System.out.println("Sum = " + sum);
System.out.println("Highest Value = " + max);
}
}
Output
![BlueJ output of Define a class to declare an array of size 20 of double datatype, accept the elements into the array and perform the following: Calculate and print the sum of all the elements. Calculate and print the highest value of the array. BlueJ output of Define a class to declare an array of size 20 of double datatype, accept the elements into the array and perform the following: Calculate and print the sum of all the elements. Calculate and print the highest value of the array.](https://cdn1.knowledgeboat.com/img/asp10/2024/1/sp4-p3.jpg)
Answered By
4 Likes
Related Questions
State the method that determines, if the specified character is an uppercase character.
Write the return data type of the following functions.
(a) startsWith( )
(b) log( )
Write a program to print following patterns.
(i)
1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
(ii)
A B A C B A D C B A E D C B A
Write a program to input and store integer elements in a double dimensional array of size 4 x 4 and find the sum of all the elements.
7 3 4 5 5 4 6 1 6 9 4 2 3 2 7 5
Sum of all the elements: 73