fork download
  1. class SmallestInArray{
  2. public static int smallest(int[] a, int total){
  3. int temp;
  4. for (int i = 0; i < total; i++)
  5. {
  6. for (int j = i + 1; j < total; j++)
  7. {
  8. if (a[i] > a[j])
  9. {
  10. temp = a[i];
  11. a[i] = a[j];
  12. a[j] = temp;
  13. }
  14. }
  15. }
  16. return a[0];
  17. }
  18. public static void main(String args[]){
  19. int a[]={1,2,5,6,3,2};
  20. System.out.println("Smallest: "+smallest(a,6));
  21. }}
Success #stdin #stdout 0.09s 27704KB
stdin
Standard input is empty
stdout
Smallest: 1