Java | max()
La méthode max() renvoie le maximum des deux arguments. L’argument peut être int, long, float, double.
Syntaxe
Cette méthode a les syntaxes suivantes:
int max(int a, int b) long max(long a, long b) float max(float a, float b) double max(double a, double b)
Paramètres
- a : Première valeur.
- b : Deuxième valeur.
Valeur de retour
La méthode renvoie le maximum des deux nombres.
Exemple :
Le code suivant montre comment utiliser la méthode max():
public class Main {
public static void main(String args[]) {
int x = 5;
int y = 10;
System.out.println("Le max est " + Math.max(x, y));
}
}
public class Main {
public static void main(String args[]) {
int x = 5;
int y = 10;
System.out.println("Le max est " + Math.max(x, y));
}
}
public class Main { public static void main(String args[]) { int x = 5; int y = 10; System.out.println("Le max est " + Math.max(x, y)); } }
Sortie:
Le max est 10