Advertisement
jgarcia123

e7.3

Nov 13th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class E73 {
  3.  
  4. public static void main(String[] args) {
  5. final int LENGTH = 100;
  6. double[] values = new double[LENGTH];
  7. int currentSize = 0;
  8.  
  9. System.out.println("Please enter values, press Q to Quit");
  10. Scanner in = new Scanner(System.in);
  11. while(in.hasNextDouble() && currentSize < values.length)
  12. {
  13. values[currentSize] =in.nextDouble();
  14. currentSize++;
  15. }
  16. double largest = values[0];
  17. double smallest = values[0];
  18. for (int i= 1; i <currentSize; i++)
  19. {
  20. if (values[i] > largest)
  21. {
  22. largest = values[i];
  23.  
  24. }
  25. for (int j = 0; j < currentSize; j++)
  26. {
  27. if (values[j] < smallest)
  28. {
  29. smallest = values[j];
  30.  
  31. }
  32. }
  33. }
  34.  
  35. for (int i = 0; i < currentSize; i++)
  36. {
  37. System.out.print(values[i]);
  38. if (values[i] == largest)
  39. {
  40. System.out.print(" <== largest value");
  41. }
  42. if (values[i] == smallest)
  43. {
  44. System.out.print(" <== smallest value");
  45. }
  46. System.out.println();
  47. }
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement