CodeGym /Blog Jawa /Acak /Metode Java.lang.Math.max().
John Squirrels
tingkat
San Francisco

# Metode Java.lang.Math.max().

Kelas Java Math ngemot metode sing dibutuhake kanggo nindakake petungan matematika. Salah sawijining pitungan umum sing dibutuhake yaiku nemokake maksimal rong nomer . Kanggo tugas iki, java wis ngenalaken java.lang.Math.max () cara. Ana sawetara bab tombol ngerti bab cara lang.Math.max () . Iku cara statis, lan mulane, sampeyan nggunakake karo jeneng kelas minangka Math.max . Iki Math.max () cara mung bisa njupuk loro bantahan, supaya sampeyan ora bisa nggunakake aplikasi iku kanggo nemokake nomer maksimum ing pesawat karo luwih saka rong nomer. Wis papat cara overloading kanggo int, pindho, float, lan jinis data dawa. Mangkene tandha-tandha metode saka 4 metode.
``````
public static int max(int a, int b)
public static double max(double a, double b)
public static long max(long a, long b)
public static float max(float a, float b)
``````
Ayo nggunakake saben cara iki ing conto kita. Nemokake Nilai Maksimum saka rong wilangan bulat.
``````
public class Main   {
public static void main(String args[])
{
int x = 40;
int y = 60;
System.out.println(Math.max(x, y));
}
}
``````
Output bakal 60. Nemokake nilai maksimum antarane loro nilai pindho.
``````
public class Main   {
public static void main(String args[])
{
double x = 15.68;
double y = -37.47;
System.out.println(Math.max(x, y));
}
}
``````
Output bakal 15,68 Nemokake nilai maksimum antarane rong nomer floating-titik.
``````
public class Main   {
public static void main(String args[])
{
float x = -21.44f;
float y = -23.32f;
System.out.println(Math.max(x, y));
}
}
``````
Output bakal -21.44f Pungkasan, ayo golek nilai maksimal antarane rong nilai dawa.
``````
public class Main   {
public static void main(String args[])
{
long x = 123456778;
long y = 453455633;
System.out.println(Math.max(x, y));
}
}
``````
Output bakal 453455633. Senajan Math.max ngijini sampeyan kanggo menehi loro nilai, sampeyan bisa improvise kanggo nemokake maksimum antarane telu utawa luwih nilai. Priksa conto ing ngisor iki.
``````
public class Main
{
public static void main(String args[])
{
int x = 40;
int y = 60;
int z = 75;
//Find the maximum among three values using max() function
System.out.println(Math.max(z, Math.max(x,y)));
}
}
``````