Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Conditional Constructs in Java

Chapter 9

Conditional Constructs in Java

Class 9 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Programs - Find the smallest of the three given integers using the min() method of the Math class


import java.util.Scanner;

 

public class SmallestOfThree {

    public static void main(String[] args) {

 

        Scanner sc = new Scanner(System.in);

 

        System.out.print("Enter first integer: ");

        int a = sc.nextInt();

 

        System.out.print("Enter second integer: ");

        int b = sc.nextInt();

 

        System.out.print("Enter third integer: ");

        int c = sc.nextInt();

 

        // Find smallest using Math.min()

        int smallest = Math.min(a, Math.min(b, c));

 

        System.out.println("\nThe smallest number is: " + smallest);

 

        sc.close();

    }

}

Output

  SAMPLE INPUT : 
Enter first integer: 25
Enter second integer: 12
Enter third integer: 18

 SAMPLE OUTPUT : 
The smallest number is: 12

Explanation

  1. Input Three Integers

int a = sc.nextInt();

int b = sc.nextInt();

int c = sc.nextInt();

  • Reads three integer values from the user.
  1. Using Math.min()

int smallest = Math.min(a, Math.min(b, c));

  • Math.min(b, c) → finds the smaller of b and c
  • Math.min(a, result) → compares a with the smaller value
  • Final result is the smallest among all three numbers
  1. Output

System.out.println("The smallest number is: " + smallest);

  • Displays the smallest integer.