Skip to content

Instantly share code, notes, and snippets.

@up1
Last active March 21, 2025 14:04
Show Gist options
  • Save up1/fcbbf4a34126ccdbcb35afa82658ed43 to your computer and use it in GitHub Desktop.
Save up1/fcbbf4a34126ccdbcb35afa82658ed43 to your computer and use it in GitHub Desktop.
Demo code of Java 24
import static java.lang.System.out;
public class Main {
void main() {
var main = new Main();
var grade = main.calculateGrade(50);
out.println(grade);
}
public String calculateGrade(int score) {
return switch (score) {
case int i when i >= 90 -> "A";
case int i when i >= 80 -> "B";
case int i when i >= 70 -> "C";
case int i when i >= 60 -> "D";
case int i when i >= 50 -> "E";
case int i -> "Failed with a score =" + score;
};
}
}
import static java.lang.System.out;
import module java.base;
public class Demo {
public static void main(String[] args) {
List<String> elements = List.of("A", "B", "C");
for (String element : elements) {
String upperCase = element.toUpperCase();
out.println(upperCase);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment