Question

Write a java program to prompt the user to enter three doubles and compute the sum...

Write a java program to prompt the user to enter three doubles and compute the sum and product. Print "The sum is 999 and the product is 999.", where 999 is replaced with the user sum and product.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new java program with name "main.java" is created, which contains following code.

main.java :

//Java program to compute sum and product of numbers
import java.util.*;//import packages
public class Main //Java Class
{ //entry point of program that is main
   public static void main(String[] args) {
   //creating object of Scanner class
   Scanner sc=new Scanner(System.in);
   //asking user to enter num1
       System.out.print("Enter number 1 : ");
       double num1=sc.nextDouble();//reading num1
       //asking user to enter num2
       System.out.print("Enter number 2 : ");
       double num2=sc.nextDouble();//reading num2
       //asking user to enter num3
       System.out.print("Enter number 3 : ");
       double num3=sc.nextDouble();//reading num3
       //compute sum of numbers
       double sum=num1+num2+num3;
       //compute product of numbers
       double product=num1*num2*num3;
       //print sum and product
       System.out.println("The sum is "+sum+" and the product is "+product+".");
   }
}

======================================================

Output : Compile and Run above program to get the screen as shown below

Screen 1 :main.java

input Enter number 1 : 10.2 Enter number 2 : 15.3 Enter number 3 :12.0 The sum is 37.5 and the product is 1872.72. ... Progra

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Write a java program to prompt the user to enter three doubles and compute the sum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT