Java Control Statement



-->

Saturday, 24 June 2017

/*To Find the Largest Number in an Array. Enter the elements of array as input. By comparing elements of array with each other we get the largest number of the array. */

import java.util.Scanner;

public class Large1 {

    public static void main(String[] args) {

        int counter = 1;
        int number;
        int largest = 0;

        Scanner input = new Scanner(System.in);

        System.out.println("Enter the number: ");
        number = input.nextInt();

        while(counter < 10)
        {
            System.out.println("Enter the number: ");
            number = input.nextInt();

            counter++;

        }


        if(number < 1)
            largest = number;


        System.out.println("the largest number is " + largest);
    }
}