Skip to content

Instantly share code, notes, and snippets.

@nherbaut
Last active September 12, 2023 13:24
Show Gist options
  • Select an option

  • Save nherbaut/22298637dbd97048ee2c5cde9b1f3e1a to your computer and use it in GitHub Desktop.

Select an option

Save nherbaut/22298637dbd97048ee2c5cde9b1f3e1a to your computer and use it in GitHub Desktop.
L2.1.7 Les conditions.1

Essayez de deviner la valeur du retour de la méthode g avant de vérifier en exécutant le code

public class TypesL2 {
static int f(int x, int y) {
if (x < y) {
System.out.println("x<y");
return y + x;
} else {
System.out.println("x >= y");
if (x < 8) {
return y + 7;
}
}
return x - 2;
}
static int g() {
int a = f(3, 4);
int b = f(a, 5);
return b;
}
public static void main(String... args) {
int returnValue = g();
System.out.println(returnValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment