CymsSoul

Untitled

Jan 25th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1.  
  2. public class Main {
  3.  
  4. public static void main(String[] args) {
  5. int[] values = {0, 6, 5, 4, 8, 7, 11, -5, 19, 2};
  6. System.out.println("smallest: " + smallest(values));
  7. }
  8.  
  9. public static int smallest(int[] array) {
  10. int smallest = array[array.length - 1];
  11.  
  12. for (int x = array.length - 1; x >= 0; x--) {
  13.  
  14. for (int y = 0; y < array.length; y++) {
  15.  
  16.  
  17. if ((array[x] < array[y]) && (array[x] < smallest)) {
  18. smallest = array[x];
  19. }
  20.  
  21. }
  22.  
  23. }
  24. return smallest;
  25. }
  26.  
  27. }
Add Comment
Please, Sign In to add comment