Sunday, July 16, 2017

Write a Java program that prompts the user to input three integer values and find the greatest value of the three values.

/**
 * Created by Jo on 7/10/2017.
 * For more exercises and lessons, visit http://shegertech.blogspot.com/
 * Chapter 4, Exercise 3
 */

import java.util.Scanner;

public class Q3Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num1 = 0, num2 = 0, num3 = 0, max = 0;

        System.out.print("First value : ");
        num1 = in.nextInt();
        System.out.print("Second value : ");
        num2 = in.nextInt();
        System.out.print("Third value : ");
        num3 = in.nextInt();

        if (num1 > num2 && num1 > num3) {
            max = num1;
            System.out.println("The maximum value is " + max);
        } else if (num2 > num1 && num2>num3) {
            max= num2;
            System.out.println("The maximum value is " + max);
        }
        else{
            max = num3;
            System.out.println("The maximum value is " + max);
        }
    }
}

Share: