Wednesday, 18 December 2019

Find The Smallest Element In Array Which Provided By User.

Solution :-
package smallElemnt;

import java.util.Scanner;

public class Main {
static int n=0;
static int arr[];
static int smallElement;
static boolean run=true;
public static void main(String[] args) {

while(run) {
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter No. Of Elements You Want To Enter In Array.");
n= sc.nextInt();
arr=new  int[n];
System.out.println("Please Enter Array Elements To Find Smallest Element.");
for(int i=0;i<n;i++)
{
arr[i]= sc.nextInt();
}

smallElement=arr[0];

for(int j=0;j<arr.length;j++)
{
if(smallElement>arr[j])
{
smallElement=arr[j];
}
}
System.out.println("Smalllest Element Is "+smallElement);
System.out.println(" Do You Want To Continue ? <Y/N>");
String Decide=sc.next();
if(Decide.equalsIgnoreCase("N"))
{
run=false;
}

}
}


}

No comments:

Post a Comment

Error While embed the video in Your website page

Error:- Refused to display '<URL>' in a frame because it set 'X-Frame-Options' to 'sameorigin Solution:- if ...