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

# Metode Java Math.min().

## Carane nemokake min () saka rong nomer ing Jawa?

Jawa menehi perpustakaan sistem dikenal minangka " java.lang.Math "Kanggo operasi Handy ekstensif. Saka trigonometri kanggo fungsi logaritma, sampeyan bisa nemokake min / max utawa malah Absolute saka nomer nggunakake cara sing diwenehake dening perpustakaan iki amarga saka macem-macem fungsi.

## Metode Math.min().

Iki minangka perwakilan biasa saka metode kasebut.
``````
Math.min(a, b)
``````
Wigati dimangerteni manawa fungsi iki nampa rong paramèter saka jinis sing padha int , dawa , float utawa pindho . Ayo kang katon ing conto eksekusi saka Math.min () cara mangertos efektif nggunakake. Priksa manawa sampeyan mbukak script ing IDE kanggo validasi output.

``````
package com.math.min.core
public class MathMinMethod {
public static void main(String[] args) {

int leenasAge = 10;
int tiffanysAge = 15;
// example of min () function
int min = Math.min(leenasAge, tiffanysAge);

System.out.print("Who's the younger sister? ");
if (min < tiffanysAge)
System.out.print("Leena ------- Age " + leenasAge);
else
System.out.print("Tiffany ------- Age " + tiffanysAge);
}
}
``````

#### Output

Sapa sing adhine? Leena ------- Umur 10

#### Panjelasan

Ing baris 8, int min = Math.min(leenasAge, tiffanysAge); int min nyimpen nomer minimal bali dening min () fungsi. Mengko kita nggunakake asil kasebut kanggo nemokake umur adhine sing luwih cilik.

``````
package com.math.min.core;
public class MathMinMethod {
public static void main(String[] args) {

double berriesSoldInKg = 15.6;
double cherriesSoldInKg = 21.3;
// example of min () function
double min = Math.min(berriesSoldInKg, cherriesSoldInKg);

System.out.println("What's the minimum weight sold?");
if (min != cherriesSoldInKg)
System.out.print("Berries: " + berriesSoldInKg + " kg");
else
System.out.print("Cherries: " + cherriesSoldInKg +"kg");
}
}
``````

#### Output

Apa bobot minimal sing didol? Woh wohan beri: 15,6 kg

#### Panjelasan

Ing baris 8, pindho min = Math.min(berriesSoldInKg, cherriesSoldInKg); pindho "min" nyimpen paling saka loro bobot. Mengko, kita mbandhingake rong ganda (jumlah ing kg) kanggo mriksa minimal saka rong woh-wohan. Asil kasebut bisa digunakake miturut syarat sampeyan ing kasus apa wae.

## Kesimpulan

Saiki sampeyan bakal bisa ngerti kabutuhan lan efisiensi metode Math.min () . Nanging, yen ana pitakon utawa kebingungan, takon maneh artikel iki. Tansah tuwuh lan latihan!

Wacan liyane:

Komentar
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION