# StrictMath nextUp() Method in Java

1. The nextUp(double num) is an inbuilt method of StrictMath class in Java which is used to get the float value that is contiguous to num in the direction of positive infinity. The nextup() method is equivalent to nextAfter(num, Double.POSITIVE_INFINITY) but nextup() runs faster than nextAfter().

Syntax:

`public static double nextUp(double num)`

Parameters: The method accepts one parameter num of double type which is the starting floating point value.

Return Value: The method returns the adjacent floating-point value closer to positive infinity. It has three special cases:

• The result is NaN when argument is a NaN.
• It returns positive infinity when the num is positive infinity..
• The result is Double.MIN_VALUE when the argument is zero.

Examples:

```Input: num = 25.18700000
Output: 25.187000000000005
```

Below program illustrates the Java.lang.StrictMath.nextUp() Method:

 `// Java praogram to illustrate the ` `// Java.lang.StrictMath.nextUp() Method ` ` `  `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``double` `num1 = ``67.1230000000``; ` `        ``double` `num2 = ``21.12``, num3 = ``0.0``; ` ` `  `        ``// Returns floating-point value adjacent to num ` `        ``double` `nextUp_Value = StrictMath.nextUp(num1); ` `        ``System.out.println(``"The Next upper value is : "` `                                       ``+ nextUp_Value); ` ` `  `        ``double` `nextUp_Value1 = StrictMath.nextUp(num2); ` `        ``System.out.println(``"The Next upper value is : "`  `                                      ``+ nextUp_Value1); ` ` `  `        ``double` `nextUp_Value2 = StrictMath.nextUp(num3); ` `        ``System.out.println(``"The Next upper value is : "`  `                                      ``+ nextUp_Value2); ` `    ``} ` `} `

Output:

```The Next upper value is : 67.12300000000002
The Next upper value is : 21.120000000000005
The Next upper value is : 4.9E-324
```
2. The nextUp(float num) is the inbuilt method of StrictMath class in Java which is used to get the floating point value that is adjacent to num in the direction of positive infinity.Float.POSITIVE_INFINITY) but nextup() runs faster than its equivalent nextAfter call.

Syntax:

`public static float nextUp(float num)`

Parameters: The method accepts one parameter num of float type which is the starting floating point value.

Return Value: The method returns the adjacent floating-point value closer to positive infinity. It has three special cases:

• The result is NaN when argument is a NaN.
• It returns positive infinity when the num is positive infinity..
• The result is Float.MIN_VALUE when the argument is zero.

Examples :

```Input: num = 15.78f
Output: 15.780000686645508
```

Below program illustrates the Java.lang.StrictMath.nextUp() Method:

 `// Java praogram to illustrate the ` `// Java.lang.StrictMath.nextUp() Method ` ` `  `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``float` `num1 = ``73``.728f; ` `        ``float` `num2 = ``51``.71f, num3 = ``0``.0f; ` ` `  `        ``// Returns floating-point value adjacent to num ` `        ``double` `nextUp_Value = StrictMath.nextUp(num1); ` `        ``System.out.println(``"The Next upper value is : "` `                                       ``+ nextUp_Value); ` ` `  `        ``double` `nextUp_Value1 = StrictMath.nextUp(num2); ` `        ``System.out.println(``"The Next upper value is : "` `                                      ``+ nextUp_Value1); ` ` `  `        ``double` `nextUp_Value2 = StrictMath.nextUp(num3); ` `        ``System.out.println(``"The Next upper value is : "` `                                      ``+ nextUp_Value2); ` `    ``} ` `} `

Output:

```The Next upper value is : 73.7280044555664
The Next upper value is : 51.71000289916992
The Next upper value is : 1.401298464324817E-45
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.