- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
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
- Input Three Integers
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
- Reads three integer values from the user.
- 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
- Output
System.out.println("The smallest number is: " + smallest);
- Displays the smallest integer.
