Find elements

Java Program to smallest among three numbers

Java Program to smallest among three numbers

In this tutorial, we discuss Java Program to the smallest among three numbers

In this program, we will discuss a simple concept of the program to find the smallest number among three numbers in the Java programming language.

In this topic, we learn how to find the smallest number from given three numbers using if statements.

Program to find the smallest and largest among three numbers

Find smallest among integer numbers

Program 1

import java.util.Scanner;
class Small_Three1{
public static void main (String args[]){
Scanner scan=new Scanner(System.in);
System.out.print("Enter the first number: ");
int num1=scan.nextInt();//get input from user for num1
System.out.print("Enter the second number: ");
int num2=scan.nextInt();//get input from user for num2
System.out.print("Enter the third number: ");
int num3=scan.nextInt();//get input from user for num3

if(num1<=num2 && num1<=num3){
    System.out.println("\n The Smallest number is: "+num1);
}
if(num2<=num1 && num2<=num3){
    System.out.println("\n The Smallest number is: "+num2);
}
if(num3<=num1 && num3<=num2){
    System.out.println("\n The Smallest number is: "+num3);
}
}
}

When the above code is compiled and executed, it produces the following results

Enter the first number: 56
Enter the second number: 23
Enter the tird number: 87

The Smallest number is 23

 

Find smallest among float numbers

Program 2

In this topic, we learn how to find the smallest number from given three float numbers using if statements.

import java.util.Scanner;
class Float_Small{
public static void main (String args[]){
Scanner scan=new Scanner(System.in);
System.out.print("Enter the first number: ");
float num1=scan.nextFloat();//get input from user for num1
System.out.print("Enter the second number: ");
float num2=scan.nextFloat();//get input from user for num2
System.out.print("Enter the third number: ");
float num3=scan.nextFloat();//get input from user for num3
if(num1<=num2 && num1<=num3){
    System.out.println("\n The Smallest number is "+num1);
}
if(num2<=num1 && num2<=num3){
    System.out.println("\n The Smallest number is "+num2);
}
if(num3<=num1 && num3<=num2){
    System.out.println("\n The Smallest number is "+num3);
}
}
}

When the above code is compiled and executed, it produces the following results

Enter the first number: 5.7
Enter the second number:2.3
Enter the third number: 8.7

The Smallest number is 2.3

Suggested for you

Operator in Java language

Data type in Java language

if statements in Java language

Nested if statements in Java language

Class and main method in Java language

 

Similar post

C code to smallest among three numbers

C++ code to smallest among three numbers

Python code to smallest among three numbers

 

Java code to find smallest of three numbers using method

C code to smallest among three numbers using function

C++ code to smallest among three numbers using function

Python code to smallest among three numbers using function

 

Java code to find smallest of three numbers using ternary operator

C code to smallest among three numbers using ternary operator

C++ code to smallest among three numbers using ternary operator

 

 

Cpp Program to display smallest among three numbers
Java Program to smallest and largest among three numbers
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

1 day ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago