program to find maximum no. in array in java language.
■》 Code link-> click 👇👇👇👇
Method 1
https://www.programiz.com/online-compiler/6hILkj1YkqGJ7
Method 2
https://www.programiz.com/online-compiler/565md3rVrowQi
■》 Program ->
import java.util.*;
public class Ved
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("enter size=");
int n =sc.nextInt();
int [] arr=new int[n];
System.out.print("enter elements of array=");
for(int i=0; i<n; i++){
arr[i]=sc.nextInt();
}
int mx=arr[0];
for(int i=1; i<n; i++){
if(mx<arr[i])
mx=arr[i];
}
System.out.println("the maximum elemnet is="+mx);
}
}
■》 output - >
enter size=5
enter elements of array=
12
4
17
34
76
the maximum elemnet is=76
Comments
Post a Comment