-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path17.Maxnumber_in_array.java
More file actions
34 lines (32 loc) · 987 Bytes
/
17.Maxnumber_in_array.java
File metadata and controls
34 lines (32 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*Question - Maximum number in array using user defined method.*/
//Ans:
import java.util.Scanner;
public class testarray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter no of elements:");
int n = sc.nextInt();
System.out.println("Enter elements:");
int[] array = new int[20];
for(int i=0;i<n;i++){
array[i]=sc.nextInt();
}
System.out.println("*** Initial Array ***");
for (int i=0; i<n; i++)
{
System.out.print(" "+array[i]);
}
System.out.println("\nMaximum number is");
max(array,n);
}
//Method to print maximun no of array
public static void max(int[] arr , int size){
int maxint = arr[0];
for (int j = 1; j < size; j++) {
if (arr[j] > maxint) {
maxint = arr[j];
}
}
System.out.println(maxint);
}
}