Solution:-
package largeElemnt;
import java.util.Scanner;
public class Main {
static int n=0;
static int arr[];
static int largeElement;
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 Largest Element.");
for(int i=0;i<n;i++)
{
arr[i]= sc.nextInt();
}
largeElement=arr[0];
for(int j=0;j<arr.length;j++)
{
if(largeElement<arr[j])
{
largeElement=arr[j];
}
}
System.out.println("Largest Element Is "+largeElement);
System.out.println(" Do You Want To Continue ? <Y/N>");
String Decide=sc.next();
if(Decide.equalsIgnoreCase("N"))
{
run=false;
}
}
}
}
package largeElemnt;
import java.util.Scanner;
public class Main {
static int n=0;
static int arr[];
static int largeElement;
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 Largest Element.");
for(int i=0;i<n;i++)
{
arr[i]= sc.nextInt();
}
largeElement=arr[0];
for(int j=0;j<arr.length;j++)
{
if(largeElement<arr[j])
{
largeElement=arr[j];
}
}
System.out.println("Largest Element Is "+largeElement);
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