Java - Get Smallest Of 3 Numbers using for loop

Description

Get Smallest Of 3 Numbers using for loop

Demo

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    System.out.print("Getting the smallest of 3 numbers:");
    @SuppressWarnings("resource")
    Scanner userInput = new Scanner(System.in);
    double num = Double.MAX_VALUE;
    DecimalFormat formater = new DecimalFormat();

    for (int i = 0; i < 3; i++) {
      double temp = userInput.nextDouble();
      if (temp < num) {
        num = temp;/*  w ww  . j  ava  2s .c o  m*/
      }
    }// end of for

    System.out.println(formater.format(num));
    
  }// end of main
}// end of class

Related Quiz