Advertisement
ralphdc09

itf103.finals-wk-14-wk-18.number02

Jun 9th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package md.WK14toWK18;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class number02 {
  6.     public static void main(String[] args) {
  7.         int[] array = {-1, 4, 0, 2, 7, -3};
  8.         System.out.println("Original number array: " + Arrays.toString(array));
  9.         int min = Integer.MAX_VALUE;
  10.         int second_min = Integer.MAX_VALUE;
  11.         for (int i = 0; i < array.length; i++) {
  12.             if (array[i] == min) {
  13.                 second_min = min;
  14.             } else if (array[i] < min) {
  15.                 second_min = min;
  16.                 min = array[i];
  17.             } else if (array[i] < second_min) {
  18.                 second_min = array[i];
  19.             }
  20.  
  21.         }
  22.         System.out.println("Second lowest number is : " + second_min);
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement