Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Task
- {
- public static void main (String [] args)
- {
- final int NUMB_OF_SONGS = 100;
- double currentSongLength;
- double shortest;
- double longest;
- int placeLongest, placeShortest;
- Scanner in = new Scanner(System.in);
- System.out.print("Enter the length of the first song: ");
- currentSongLength = in.nextDouble();
- longest = currentSongLength;
- shortest = currentSongLength;
- placeLongest = 1;
- placeShortest = 1;
- for(int i = 2; i <= NUMB_OF_SONGS; i++)
- {
- System.out.print("Enter the length of song " + i + ": ");
- currentSongLength = in.nextDouble();
- if (currentSongLength > longest)
- {
- longest = currentSongLength;
- placeLongest = i;
- }
- if (currentSongLength < shortest)
- {
- shortest = currentSongLength;
- placeShortest = i;
- }
- }
- System.out.println("The number of the longest song is " + placeLongest);
- System.out.println("The number of the shortest song is " + placeShortest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement