Advertisement
Guest User

Targil

a guest
Feb 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class Task
  3. {
  4. public static void main (String [] args)
  5. {
  6.     final int NUMB_OF_SONGS = 100;
  7.     double currentSongLength;
  8.     double shortest;
  9.     double longest;
  10.     int placeLongest, placeShortest;
  11.     Scanner in = new Scanner(System.in);
  12.     System.out.print("Enter the length of the first song: ");
  13.     currentSongLength = in.nextDouble();
  14.  
  15.     longest = currentSongLength;
  16.     shortest = currentSongLength;  
  17.     placeLongest = 1;
  18.     placeShortest = 1;
  19.  
  20. for(int i = 2; i <= NUMB_OF_SONGS; i++)
  21.     {
  22.     System.out.print("Enter the length of song " + i + ": ");
  23.     currentSongLength = in.nextDouble();
  24.     if (currentSongLength > longest)
  25.     {      
  26.     longest = currentSongLength;
  27.     placeLongest = i;
  28.     }
  29.     if (currentSongLength < shortest)
  30.     {      
  31.     shortest = currentSongLength;
  32.     placeShortest = i;
  33.     }
  34. }
  35.     System.out.println("The number of the longest song is " + placeLongest);
  36.     System.out.println("The number of the shortest song is " + placeShortest);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement