public class Survive {
private Survive internalInstance = new Survive();
public Survive() throws Exception {
throw new Exception("I'm not coming out");
}
public static void main(String[] args) {
try {
Survive b = new Survive();
System.out.println("WIN!");
} catch (Exception ex) {
System.out.println("LOSE!");
}
}
}#java #quest
public class Quest {
public static void main(String[] args) {
int[][] tests = {
{6, 5, 4, 3, 2, 1},
{1, 2},
{1, 2, 3},
{1, 2, 3, 4},
{1}
};
int n = 0;
try {
int i = 0;
while (true) {
if (thirdElementIsThree(tests[i++])) n++;
}
} catch (ArrayIndexOutOfBoundsException e) {
}
System.out.println(n);
}
private static boolean thirdElementIsThree(int[] a) {
return (a.length >= 3) & (a[2] == 3);
}
}
#java #quest
❤5
public class Quest {
private final String name;
Quest(String name) {
this.name = name;
}
private String name() {
return name;
}
private void reproduce() {
new Quest("reproduce") {
void printName() {
System.out.println(name());
}
}.printName();
}
public static void main(String[] args) {
new Quest("main").reproduce();
}
}#java #quest
❤3
enum Month {
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER
}
public class Quest {
public static void main(String[] args) {
Month m = Month.JANUARY;
String season = switch (m) {
case DECEMBER, JANUARY, FEBRUARY -> "Winter";
case MARCH, APRIL, MAY -> "Spring";
case JUNE, JULY, AUGUST -> "Summer";
case SEPTEMBER, OCTOBER -> "Autumn";
};
System.out.println(season);
}
}#java #quest
❤8👎1
public class Quest {
public static void main(String[] args) {
System.out.print(op1() + op2() * op3());
}
private static int op1() {
System.out.print(1);
return 1;
}
private static int op2() {
System.out.print(2);
return 2;
}
private static int op3() {
System.out.print(3);
return 3;
}
}#java #quest
👍3👎2❤1