fork download
  1. // Find the smallest number in an array
  2. // declaring array using scanner
  3.  
  4. // Scanner sc = new Scanner(System.in);
  5. // int n = sc.nextInt();
  6.  
  7.  
  8. // int[] arr = new int[10];
  9. // System.out.println("Enter the elements of arr");
  10.  
  11.  
  12. // for(int i=0;i<=n;i++){
  13. // System.out.println(arr[i]+ " ");
  14. // }
  15.  
  16.  
  17.  
  18. import java.util.*;
  19. public class Main{
  20. public static void main(String[] args){
  21. int [] arr = {2,6,1,3,4,5};
  22.  
  23. int smallest = arr[0];
  24. for(int i=1;i<arr.length;i++){
  25. if(arr[i]<smallest){
  26. smallest = arr[i];
  27. }
  28. }
  29. System.out.println("Smallest num:" +smallest);
  30. }
  31. }
  32.  
  33.  
  34.  
Success #stdin #stdout 0.15s 53648KB
stdin
Standard input is empty
stdout
Smallest num:1