Algorithm Sample - Finding the biggest and smallest number


package algorithmsample29;

import java.util.Scanner;

/**
 *
 * @author Nurhak
 */
public class AlgorithmSample29 {

    public static void main(String[] args) {
        int number = 0;
        int biggestNumber = 0;
        int smallestNumber = 0;
        String data = "";
        try {
            Scanner scan = new Scanner(System.in);
            for (int i = 1; i <= 10; i++) {
                System.out.println("Enter the number " + i);
                data = scan.nextLine();
                number = Integer.parseInt(data);
                if (number > biggestNumber) {
                    biggestNumber = number;
                }
                if (number < smallestNumber) {
                    smallestNumber = number;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("----------------");
        System.out.println("The biggest number is: " + biggestNumber);
        System.out.println("----------------");
        System.out.println("The smallest number is: " + smallestNumber);

    }
}

Comments

Popular posts from this blog

Solution for "Can not obtain Oracle client information from registry"

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"