java

How to Find the Smallest of 3 Numbers in Java

In this tutorial, we are going to see how to find the smallest of 3 numbers in Java. To understand this program, you must have knowledge of the if-else-if statement in Java.
 

Java Program to Find the Smallest of 3 Numbers
public class Main{

  public static void main(String[] args) {

      int n1 = 3, n2 = 10, n3 = 5;

      if( n1 <= n2 && n1 <= n3)
          System.out.println("The smallest number is: "+n1);
      else if (n2 <= n1 && n2 <= n3)
          System.out.println("The smallest number is: "+n2);
      else
          System.out.println("The smallest number is: "+n3);
  }
}

Output:

The smallest number is: 3
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *