Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Java min Function

by suresh

The Java min Function is one of the Java Math Library functions, which is to return the Minimum or Smaller value from the given two arguments.

Java min Function Syntax

The basic syntax of the Math.min in Java Programming language is as shown below:

Math.min(data_type x, data_type y);

Java Programming provides four different functions to find the Minimum or Smaller value from the given two arguments.

The following function will accept positive or negative integer value as the first and second argument and returns the Smaller value of integer type.

static int min(integer x, intger y); //Return Type is Integer

// In order to use in program: 
Math.min(int x, int y);

This Java min double function will accept the negative or positive double value and returns the Smaller value of double type.

static double min(double x, double y); //Return Type is double

// In order to use in program: 
Math.min(double x, double y);

It accepts positive or negative float value as the first and second arguments. It returns the Smaller value of float type.

static float min(float x, float y); //Return Type is float

// In order to use in program: 
Math.min(float x, float y);

The following function allows positive or negative long value and returns the Smaller value of Long type.

static long min(long x, long y); //Return Type is long

// In order to use in program: 
Math.long(long x, long y);

Java min Function Example

In this example, we use the Java Math.min function to find the Minimum or Smaller value from a different set of data types and display the output.

// Java Math.min Function
package MathFunctions;
public class MinMethod {
 public static void main(String[] args) {
 double b = 10.9666, c = 14.6674, d = -9.474, e = -14.9865;
 float g = 1.23f, h = 4.809f, i = -7.89f, j = -6.54f;
 long  k = 200, l = 400, m = -300, n = -100;
 
 System.out.println("Minimum value of Positive Integer: " + Math.min(10, 20));
 System.out.println("Minimum value of Negative Integer: " + Math.min(-20, -60));
 System.out.println("Minimum value of both Positive & Negative: " + Math.min(10, -20));
 
 System.out.println("\nMinimum value of Positive Double: " + Math.min(b, c));
 System.out.println("Minimum value of Negative Double: " + Math.min(d, e));
 System.out.println("Minimum value of both Positive & Negative: " + Math.min(b, e));
 
 System.out.println("\nMinimum value of Positive Float: " + Math.min(g, h));
 System.out.println("Minimum value of Negative Float: " + Math.min(i, j));
 System.out.println("Minimum value of both Positive & Negative: " + Math.min(h, i));
 
 System.out.println("\nMinimum value of Positive Number: " + Math.min(k, l));
 System.out.println("Minimum value of Negative Number: " + Math.min(m, n));
 System.out.println("Minimum value of both Positive & Negative: " + Math.min(k, n));
 }
}

OUTPUT

Java min Function 1

ANALYSIS

First, we used the Java Math.min Function directly on both the Positive integer and negative integer values. The following statements will call the min method of integer type ( static int min(integer a, integer b) ) and find the smallest among the values.

System.out.println("Minimum value of Positive Integer: " + Math.min(10, 20));
System.out.println("Minimum value of Negative Integer: " + Math.min(-20, -60));
System.out.println("Minimum value of both Positive & Negative: " + Math.min(10, -20));

Next, We used the Math.min Function on variable b, c, d, and e (they belong to double type). The following statements will call the min method of double type ( static double min(double a, double b) ) and find the smallest among the values.

System.out.println("\nMinimum value of Positive Double: " + Math.min(b, c));
System.out.println("Minimum value of Negative Double: " + Math.min(d, e));
System.out.println("Minimum value of both Positive & Negative: " + Math.min(b, e));

Next, We used the Java min Function on variable g, h, i, and j (they belong to float type). The following statements will call the min method of float type ( static float min(float a, float b) ) and find the smallest among the values.

System.out.println("\nMinimum value of Positive Float: " + Math.min(g, h));
System.out.println("Minimum value of Negative Float: " + Math.min(i, j));
System.out.println("Minimum value of both Positive & Negative: " + Math.min(h, i));

Last, We used the min Math function on variable k, l, m, and n (they belong to long type). The following statements will call the min method of long type ( static long min(long a, long b) ) and find the smallest among the values.

System.out.println("\nMinimum value of Positive Number: " + Math.min(k, l));
System.out.println("Minimum value of Negative Number: " + Math.min(m, n));
System.out.println("Minimum value of both Positive & Negative: " + Math.min(k, n));

Placed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy