Advertisement
Vladkoheca

SecondSmallestNum.java

Dec 10th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.  
  8.         System.out.print("Type the length of the massive: ");
  9.         int n = Integer.parseInt(sc.nextLine());
  10.         int[] array = new int[n];
  11.  
  12.         for (int i = 0; i < n; i++) {
  13.             System.out.print("Type number " + (i + 1) + ": ");
  14.             array[i] = Integer.parseInt(sc.nextLine());
  15.         }
  16.         Arrays.sort(array);
  17.         System.out.println("Second smallest element in the array is: " + array[1]);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement