forked from ishanjogalekar/Java-Programs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.Maxnumber_in_array.java
More file actions
Latest commit
34 lines (32 loc) · 987 Bytes
/
Copy path17.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:
importjava.util.Scanner;
publicclasstestarray {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
System.out.println("Enter no of elements:");
intn = sc.nextInt();
System.out.println("Enter elements:");
int[] array = newint[20];
for(inti=0;i<n;i++){
array[i]=sc.nextInt();
}
System.out.println("*** Initial Array ***");
for (inti=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
publicstaticvoidmax(int[] arr , intsize){
intmaxint = arr[0];
for (intj = 1; j < size; j++) {
if (arr[j] > maxint) {
maxint = arr[j];
}
}
System.out.println(maxint);
}
}