Home ICSE Computer Applications Class 10 – Previous Year Question Papers & Solutions / Programs / Define a class to declare an array of size twenty of double datatype, accept the elements into the array and perform the following : Calculate and print the product of all the elements.Print the square of each element of the array.
🚀 Programming Example

Define a class to declare an array of size twenty of double datatype, accept the elements into the array and perform the following :

Calculate and print the product of all the elements.
Print the square of each element of the array.

👁 83 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.
No previous program
No next program

📌 Information & Algorithm

Given Input:


Expected Output:


💻 Program Code

import java.util.Scanner;

public class RansariSDADouble
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        double  arr[] = new double[20];
        int l = arr.length;
        double p = 1.0;
        
        System.out.println("Enter 20 numbers:");
        for (int i = 0; i < l; i++)
        {
            arr[i] = in.nextDouble();
        }
        
        for (int i = 0; i < l; i++)
        {
            p *= arr[i];
        }        
        System.out.println("Product = " + p);
        
        System.out.println("Square of array elements :");
        for (int i = 0; i < l; i++)
        {
            double sq = Math.pow(arr[i], 2);
            System.out.println(sq + " ");
        }  
    }
}
                        
No previous program
No next program
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.