Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package md.WK14toWK18;
- import java.util.Arrays;
- public class number02 {
- public static void main(String[] args) {
- int[] array = {-1, 4, 0, 2, 7, -3};
- System.out.println("Original number array: " + Arrays.toString(array));
- int min = Integer.MAX_VALUE;
- int second_min = Integer.MAX_VALUE;
- for (int i = 0; i < array.length; i++) {
- if (array[i] == min) {
- second_min = min;
- } else if (array[i] < min) {
- second_min = min;
- min = array[i];
- } else if (array[i] < second_min) {
- second_min = array[i];
- }
- }
- System.out.println("Second lowest number is : " + second_min);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement