HOW TO FIND SMALLEST ELEMENT OF AN ARRAY IN JAVA?
INPUT:-
import java.util.Scanner;
public class example{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n[]= new int[5];
int i,t;
System.out.println("Enter the array element : ");
for(i=0;i<5;i++)
{
n[i]=sc.nextInt();
}
t=n[0];
for(i=0;i<5;i++){
if(n[i]<t)
t=n[i];
}
System.out.println("The smallest number is : " + t);
}
}
0 Comments