Maximum
Q. Find the Largest or Maximum number from a given number.
Example:-
input:- 1,2,25,0,2
output:-25
Program Solution
import java.util.Scanner;
public class Main
{
public static void main (String[]args)
{
System.out.println ("Finding maximum number");
System.out.println ("Enter array size");
Scanner input1 = new Scanner (System.in);
int num1 = input1.nextInt ();
int[] arr = new int[10];
System.out.println ("Enter array values");
for (int i = 0; i < num1; i++)
{
arr[i] = input1.nextInt ();
}
int max = arr[0];
int ans=MaxValue(arr,max,num1);
System.out.println ("Max value is = " + ans);
}
public static int MaxValue(int[] arr,int max ,int num1)
{
for (int j = 0; j < num1; j++)
{
if (arr[j] > max)
{
max = arr[j];
}
}
return max;
}
}
Output:
Finding maximum number
Enter array size
5
Enter array values
1
2
25
0
2
Max value is = 25