The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java program to find maximum of two numbers using Math.max()

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Java program to find maximum of two numbers using Math.max() Posted: Apr 23, 2017 12:45 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Java program to find maximum of two numbers using Math.max()
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
  • We can find maximum of two numbers by using if condition check.
  • In java.lang.Math class also having a method Math.max() which will take two numbers and returns maximum number.
  • We have separate methods for int , float , double and long.




  1.  public static double max(double a, double b)

Java program to find maximum of two double values using Math.max() method.


  1. package com.mathmax;
  2. public class MathMAx {
  3.     
  4.     /**
  5.      * Math.max() method in java
  6.      * @author www.instanceofjava.com
  7.      */
  8.  
  9.   public static void main(String[] args) {
  10.         
  11.         
  12.         double a = 234567;
  13.         double b =234557;
  14.      
  15.         double x = 764554;
  16.         double y =764464;
  17.         
  18.         System.out.println("Math.max(" + a + "," + b + ")=" + Math.max(a, b));
  19.         System.out.println("Math.max(" + x + "," + y + ")=" + Math.max(x, y));
  20.         
  21.     }
  22.  
  23. }
Output:

  1. Math.pow(3.0,4.0)=81.0
  2. Math.pow(4.0,3.0)=64.0
  3. Math.pow(4,2)=16.0

Java program to find maximum of two float values using Math.max() method.



math.max method in java float


Java program to find maximum of two int values using Math.max() method.
 
  1. package com.mathmax;
  2. public class MathMAx {
  3.     
  4.     /**
  5.      * Math.max() method in java
  6.      * @author www.instanceofjava.com
  7.      */
  8.  
  9. public static void main(String[] args) {
  10.         
  11.         System.out.println( Math.max(1, 1));
  12.         System.out.println( Math.max(1, 2));
  13.         System.out.println(Math.max(1.222f, 1.223f));
  14.         System.out.println(Math.max(1.222, 1.223));
  15.         
  16.     }
  17.  
  18. }

Output:

  1. 1
  2. 2
  3. 1.223
  4. 1.223

Read: Java program to find maximum of two numbers using Math.max()

Topic: Spanning goes private, what might happen next? Previous Topic   Next Topic Topic: SOAP and RESTful - Best Books to Learn Web Service in Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use