ICSE 2022 SEM-2 QUESTION 4 SOLVED

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

 * following: 1. Calculate and print the product of all the elements

 * 2. Print the square of each element of the array

 */

import java.util.*;

class QUESTION_4

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        double n[]=new double[20];

        double p=1;

        System.out.println("Enter 20 elements :");

        for(int i=0;i<5;i++)

        {

            n[i]=sc.nextDouble();

            p=p*n[i];

        }

        System.out.println("Square of all the elements:");

        System.out.println("Element\t\tSquare");

        System.out.println("-------\t\t------");

        for(int i=0;i<5;i++)

        {

            System.out.println("  "+n[i]+"\t\t\t"+n[i]*n[i]);

        }

        System.out.println("Product of all the elements: "+p);

    }

}

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...