//find nd smallest among n numbers import java.util.Scanner; public class Numbers { public static void main(String[] args) { int n, temp, min = Integer.MAX_VALUE, secondMin = Integer.MAX_VALUE; Scanner ip = new Scanner(System.in); System.out.print("Enter the number of inputs: "); n = ip.nextInt(); for (int i = 1; i <= n; i++) { System.out.print("Enter number " + i + ": "); temp = ip.nextInt(); if (temp <= min) { secondMin = min; min = temp; } else if (temp <= secondMin) secondMin = temp; } System.out.println("The smallest number is " + min); System.out.println("The second smallest number is " + secondMin); ip.close(); } } OUTPUT: Enter the number of inputs: 5 Enter number 1: 3 Enter number 2: 7 Enter number 3: 2 Enter number 4: 7 Enter number 5: 1 The smallest number is 1 The second smallest number is 2