Advertisement
Spocoman

Movie Ratings

Sep 8th, 2024
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int movies = Integer.parseInt(scanner.nextLine());
  7.         String movie, maxMovie = "", minMovie = "";
  8.         double rating, maxRating = 0, minRating = 10, totalRating = 0;
  9.  
  10.         for (int i = 0; i < movies; i++) {
  11.             movie = scanner.nextLine();
  12.             rating = Double.parseDouble(scanner.nextLine());
  13.  
  14.             if (rating > maxRating) {
  15.                 maxMovie = movie;
  16.                 maxRating = rating;
  17.             }
  18.             if (rating < minRating) {
  19.                 minMovie = movie;
  20.                 minRating = rating;
  21.             }
  22.             totalRating += rating;
  23.         }
  24.  
  25.         System.out.printf("%s is with highest rating: %.1f\n", maxMovie, maxRating);
  26.         System.out.printf("%s is with lowest rating: %.1f\n", minMovie, minRating);
  27.         System.out.printf("Average rating: %.1f\n", totalRating / movies);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement