I want a program can read in three integers then prints out their sum and produc
ID: 3675227 • Letter: I
Question
I want a program can read in three integers then prints out their sum and product and average
for my input,it should have one or more lines of numbers that have been typed in by the user. Each line is to
have exactly three real numbers.I would like to sue in.nextDouble() to read a number and after reading there doubles. how do i discard rest of spaces?
for my output it should have for each line,the numbers that had been read in separated by a single space followed by their sum, product, and
average separated by a space.
Each number is to be printed using "%.2e" format. I would use S.O.P("%.2e %.2e ", num1, num2);
Explanation / Answer
import java.util.Scanner;
public class HelloWorld
{
public static void main ( String arguments[] )
{
Scanner in = new Scanner( System.in ) ;
double no1 ;
double no2 ;
double no3 ;
double total ;
double avg ;
double mult ;
System.out.print ( " Type 1st Integer: " ) ;
no1 = in.nextDouble ( ) ;
System.out.print(" Type 2nd Integer: " ) ;
no2 = in.nextDouble ( ) ;
System.out.print ( " Type 3rd Integer: " ) ;
no3 = in.nextDouble ( ) ;
total = no1 + no2 + no3 ;
avg = total / 3 ;
mult = no1 * no2 * no3 ;
System.out.println ( " The total is " + total ) ;
System.out.println ( " The average is " + avg ) ;
System.out.println ( " The product is " + mult ) ;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.