Java program that reads in three floating­ point numbers and prints the largest of the three inputs
Posted by Samath
Last Updated: February 12, 2021

Write a program that reads in three floating­point numbers and prints the largest of the three inputs without using the max function. For example:
     Enter a number: 4
     Enter a number: 9
     Enter a number: 2.5
     The largest number is 9.0

Code:

import java.util.Scanner;

public class Main
{
    public static void main(String[] args) {
		double num1;
        double num2;
        double num3;
        double largest;
	    
        Scanner input = new Scanner(System.in);
        
        System.out.println("Enter first number: ");
        num1 = input.nextDouble();
        
        System.out.println("Enter second number: ");
        num2 = input.nextDouble();
        
        System.out.println("Enter third number: ");
        num3 = input.nextDouble();
        input.close();
		
		if (num1 >= num2 && num1 > num3) {
			largest = num1;
		} else if (num2 > num1 && num2 >= num3){
			largest = num2;
		} else {
			largest = num3;
		}
		System.out.println("Largest number: " + largest);
	}
}