Write a Java method to find the smallest number among three numbers


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

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.Scanner;
  2. public class Javaexcercise {
  3.  
  4. public static void main(String[] args)
  5. {
  6. Scanner in = new Scanner(System.in);
  7. System.out.print("Input the first number: ");
  8. double num1 = in.nextDouble();
  9. System.out.print("Input the Second number: ");
  10. double num2 = in.nextDouble();
  11. System.out.print("Input the third number: ");
  12. double num3 = in.nextDouble();
  13. System.out.print("The smallest value is " + smallestnumber(num1, num2, num3)+"\n" );
  14. }
  15.  
  16. public static double smallestnumber(double num1, double num2, double num3)
  17. {
  18. return Math.min(Math.min(num1, num2), num3);
  19. }
  20. }

Result

java techstudy.org

     





Related Topics




Popular Posts