Structure of the Problem Requirements
In this problem we will learn how to find the Maximum number in array in Java programming. The program will asked user to enter his number and then give the maximum number as return on his first index of array. A simple IF condition is used for this program which replace the Max number every time whenever array num is bigger then it. here is the source code of this program it will clear your confusion more :).
Source Code
package com.ancodingpoints.www;
import java.util.Scanner;
public class Find_Max {
public static void main (String [] args )
{
Scanner input = new Scanner (System.in);
int num [] = new int [5];
int max = num[0];
for ( int i = 0; i < 5; i++)
{
System.out.println(" Enter your Number : ");
num[i] = input.nextInt();
if (num[i] > max )
{
max = num[i];
}
}
System.out.println(" The Maximum Integer is :" + max);
}
}
Output of the Program
Return Maximum Number |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
0 comments:
Post a Comment