Advertisement
psi_mmobile

Untitled

May 27th, 2022
582
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         int numberOfMovies = Integer.parseInt(scanner.nextLine());
  5.         String movieName = null;
  6.         double movieRating = 0.0;
  7.         double averageMovieRating = 0.0;
  8.        
  9.         String minMovieName = null;
  10.         double minMovieRating = Double.MAX_VALUE;
  11.        
  12.         String maxMovieName = null;
  13.         double maxMovieRating = Double.MIN_VALUE;
  14.        
  15.         for (int i = 1; i <= numberOfMovies; i++) {
  16.             movieName = scanner.nextLine();
  17.             movieRating = Double.parseDouble(scanner.nextLine());
  18.             if (movieRating < minMovieRating) {
  19.                 minMovieRating = movieRating;
  20.                 minMovieName = movieName;
  21.             }
  22.             if (movieRating > maxMovieRating) {
  23.                 maxMovieRating = movieRating;
  24.                 maxMovieName = movieName;
  25.             }
  26.             averageMovieRating += movieRating;
  27.         }
  28.         System.out.printf("%s is with the highest rating: %.1f\n", maxMovieName,maxMovieRating);
  29.         System.out.printf("%s is with the lowest rating: %.1f\n", minMovieName,minMovieRating);
  30.         System.out.printf("Average rating: %.1f", (double)averageMovieRating / numberOfMovies);
  31.     }
  32. }
Advertisement
RAW Paste Data Copied
Advertisement