Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- int numberOfMovies = Integer.parseInt(scanner.nextLine());
- String movieName = null;
- double movieRating = 0.0;
- double averageMovieRating = 0.0;
- String minMovieName = null;
- double minMovieRating = Double.MAX_VALUE;
- String maxMovieName = null;
- double maxMovieRating = Double.MIN_VALUE;
- for (int i = 1; i <= numberOfMovies; i++) {
- movieName = scanner.nextLine();
- movieRating = Double.parseDouble(scanner.nextLine());
- if (movieRating < minMovieRating) {
- minMovieRating = movieRating;
- minMovieName = movieName;
- }
- if (movieRating > maxMovieRating) {
- maxMovieRating = movieRating;
- maxMovieName = movieName;
- }
- averageMovieRating += movieRating;
- }
- System.out.printf("%s is with the highest rating: %.1f\n", maxMovieName,maxMovieRating);
- System.out.printf("%s is with the lowest rating: %.1f\n", minMovieName,minMovieRating);
- System.out.printf("Average rating: %.1f", (double)averageMovieRating / numberOfMovies);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement