java

Java Program to Find Largest of Three Numbers

In this tutorial, we are going to see how to find the largest 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 Largest of Three 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 largest number is: "+n1);
      else if (n2 >= n1 && n2 >= n3)
          System.out.println("The largest number is: "+n2);
      else
          System.out.println("The largest number is: "+n3);
  }
}

Output:

The largest number is: 10
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 *