Ticker

6/recent/ticker-posts

Java (Smallest Value In Array)

SMALLEST VALUE IN AN ARRAY



PROGRAM TO FIND SMALLEST  VALUE IN ARRAY
import java.util.Scanner; //Import the Scanner class
class Smallest_value
{
public static void main(String args[])
{
int num[] = new int[60];
int i, S, size;

System.out.print("Enter array size: ");
Scanner in = new Scanner(System.in);
size=in.nextInt();

//Insert value in size variable at run time
//size=in.nextInt(); 


System.out.println("Enter values in array:");
//Scanner in = new Scanner(System.in);
for(i=0; i<size; i++)
{
num[i]=in.nextInt();
}
L=num[0];

//Loop to find the smallest value.
for(i=0; i<size; i++)
{
if(S > num[i])
S = num[i];
}

System.out.println("Smallest value is: "+L);
}

}


- - - PROGRAM OUTPUT - - -







Post a Comment

0 Comments