Answer to Question #114400 in Java | JSP | JSF for Paul

Question #114400
Write the complete java program called Temperature that includes a for loop structure,
prompting the user to enter 5 temperature values. The program should add up each
temperature entered within the loop and this is stored in a variable called total. Using a
system statement, output the total temperature value and the average temperature value.
1
Expert's answer
2020-05-07T13:15:42-0400
import java.util.Scanner;

public class Temperature {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double total = 0;
        for (int i = 0; i < 5; i++)
        {
            System.out.println("Enter temperature: ");
            double temperature = scanner.nextDouble();
            total += temperature;

        }
        System.out.println("The total temperature = " + total);
        System.out.println("The average temperature = " + total / 5);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS