Write a Java program to take three numbers from the user and print the greatest number


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  1. import java.util.Scanner;
  2. public class JavaExcercise {
  3.  
  4. public static void main(String[] args) {
  5. Scanner in = new Scanner(System.in);
  6.  
  7. System.out.print("Enter 1st number: ");
  8. int num1 = in.nextInt();
  9.  
  10. System.out.print("Enter 2nd number: ");
  11. int num2 = in.nextInt();
  12.  
  13. System.out.print("Enter 3rd number: ");
  14. int num3 = in.nextInt();
  15.  
  16.  
  17. if (num1 > num2)
  18. if (num1 > num3)
  19. System.out.println("The greatest: " + num1);
  20.  
  21. if (num2 > num1)
  22. if (num2 > num3)
  23. System.out.println("The greatest: " + num2);
  24.  
  25. if (num3 > num1)
  26. if (num3 > num2)
  27. System.out.println("The greatest numbers is : " + num3);
  28. }
  29. }

Result

java techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.