KnowledgeBoat Logo

Computer Applications

Write a program to input a set of any 10 integer numbers. Find the sum and product of the numbers. Join the sum and product to form a single number. Display the concatenated number.
[Hint: let sum=245 and product = 1346 then the number after joining sum and product will be 2451346]

Java

Java Library Classes

86 Likes

Answer

import java.util.Scanner;

public class KboatSumProdConcat
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter 10 integers");
        long sum = 0, prod = 1;
        for (int i = 0; i < 10; i++) {
            int n = in.nextInt();
            sum += n;
            prod *= n;
        }
        
        String s = Long.toString(sum) + Long.toString(prod);
        long r = Long.parseLong(s);
        
        System.out.println("Concatenated Number = " + r);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to input a set of any 10 integer numbers. Find the sum and product of the numbers. Join the sum and product to form a single number. Display the concatenated number. [Hint: let sum=245 and product = 1346 then the number after joining sum and product will be 2451346]

Answered By

32 Likes


Related Questions