Richard_Sekol

ex7.3

Nov 15th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package chap7;
  2. import java.util.Scanner;
  3. public class EX3 {
  4. public static void main(String[] args) {
  5. final int LENGTH = 100;
  6. int[] values = new int[LENGTH];
  7. int currentSize = 0;
  8.  
  9. System.out.println("enter valuess");
  10. Scanner in = new Scanner(System.in);
  11. while (in.hasNextDouble() && currentSize < values.length) {
  12. values[currentSize] = in.nextInt();
  13. currentSize++;
  14. }
  15. in.close();
  16.  
  17. int largest = values[0];
  18. int smallest = values[0];
  19. for (int i = 1; i < currentSize; i++) {
  20. if (values[i] > largest) {
  21. largest = values[i];
  22. }
  23. if (values[i] < smallest) {
  24. smallest = values[i];
  25. }
  26. }
  27.  
  28. for (int i = 0; i < currentSize; i++) {
  29. System.out.print(values[i]);
  30. if (values[i] == largest && smallest != largest) {
  31. System.out.print(" is the largest value");}
  32. else if (values[i] == smallest && smallest != largest)
  33. {
  34. System.out.print(" is the smallest value");}
  35. else
  36. {
  37. System.out.print(" is the smallest and largest value");}
  38. System.out.println();}
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment