Answers for "java Program calculates the largest and the smallest of five integers entered one at a time."

0

difference between greatest and smallest number in java

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int greatest;
        int smallest;

        System.out.print("Enter three numbers: ");
        int num1 = scanner.nextInt();
        int num2 = scanner.nextInt();
        int num3 = scanner.nextInt();

        if(num1 > num2 && num1 > num3)
            greatest =num1;

        else if(num2 > num1 && num2 > num3)
            greatest =num2;

        else
            greatest = num3;

        if(num1 < num2 && num1 < num3)
            smallest =num1;

        else if(num2 < num1 && num2 < num3)
            smallest =num2;

        else
            smallest = num3;

        int difference = greatest - smallest;

        System.out.printf("The difference of %d and %d is %d ",greatest,smallest,difference);
    }
}
Posted by: Guest on June-23-2021

Code answers related to "java Program calculates the largest and the smallest of five integers entered one at a time."

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language