In this problem we will learn how to find the biggest number in array. 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.
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); } }
0 comments:
Post a Comment