Computer Science, asked by saaranshmohanty2, 14 days ago

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. in java grade 10 icse ​

Answers

Answered by samarthkrv
90

Answer:

import java.util.*;

public class Main

{

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    double sum = 0;

 double[] arr = new double[20];

 System.out.println("Ënter all 20 elements in the array:");

     for(int i = 0; i < 20; i++){

         arr[i] = sc.nextDouble();

         sum = sum + arr[i];

     }

     Arrays.sort(arr);

     System.out.println("The sum of the 20 numbers is " + sum + " the largest element is " + arr[arr.length-1]);

}

}

Explanation:

Answered by preethalee1
6
Answer:
import java.io.*;
import java.util.Scanner;
public class Max_val
{
public static void main (String [] args)//main program
{
double sum=0, max=0;
Scanner sc=new Scanner(System.in);
double ar []=new double [ 20 ];
for (i=0; i < 20; i++)
{
System.out.println("Enter the number" +(i+1));
n[i]=sc.nextDouble();
sum=sum+ n[i];
if (n[i]>max)
max=n[i];
}
System.out.println("The sum of 20 numbers="+sum);
System.out.println("The highest value ="+max);
}// end of main
}// end of class
Similar questions