public class Test {
public static void main(String[] args) {
int x = 1;
System.out.println("x+1 = " + x+1);
}
}❤🔥1❤1👍1
🎉5
public class Test {
public static void main(String[] args) {
String s = null;
if (s != null & s.length() > 0) {
System.out.println("YES!");
} else {
System.out.println("NO!");
}
}
}❤1👍1
🎉1
public class Test {
public static void main(String[] args) {
int x = 5;
int y = 10;
int result = add(x, y) * multiply(x, y);
System.out.println(result);
}
public static int add(int a, int b) {
try {
return a + b;
} finally {
return a - b;
}
}
public static int multiply(int a, int b) {
try {
return a * b;
} finally {
return a / b;
}
}
}❤1
🎉2
public class Test {
public static void main(String[] args) {
int i = 1;
inc(i);
System.out.println(i);
}
private static void inc(int num) {
num++;
}
}❤2
🎉2
public class Test {
public static void main(String[] args) {
int j = 0;
for (int i = 0; i < 10; i++) {
j = j++;
}
System.out.println(j);
}
}❤5👍1👎1
🎉3🔥2❤1
import java.util.List;
public class Test {
public static void main(String[] args) {
List<Integer> ints = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
ints.stream()
.filter(i -> i % 2 == 0)
.skip(1)
.limit(1)
.forEach(System.out::print);
}
}
❤2
🎉6❤1
public class Test {
public static void main(String[] args) {
int i = Integer.MAX_VALUE;
i++;
if (i == 0) {
System.out.println("ZERO");
} else if (i == Integer.MIN_VALUE) {
System.out.println("MIN");
}
}
}👍3❤2
🎉2❤1
public class Test {
public static final int END = Integer.MAX_VALUE;
public static final int START = END - 100;
public static void main(String[] args) {
int count = 0;
for (int i = START; i <= END; i++) count++;
System.out.println(count);
}
}❤3
🎉5
public class Test {
public static void main(String[] args) {
int minutes = 0;
for (int ms = 0; ms < 60 * 60 * 1000; ms++) {
if (ms % 60 * 1000 == 0) {
minutes++;
}
}
System.out.println(minutes);
}
}❤3
👍4❤1🎉1
public class Test {
public static void main(String[] args) {
Integer a = 128;
Integer b = 128;
System.out.print(a == b);
System.out.print("-");
Integer x = 1;
Integer y = 1;
System.out.print(x == y);
}
}❤4
❤2🔥1
public class Test {
private Test internalInstance = new Test();
public Test() throws Exception {
throw new Exception("I'm not coming out");
}
public static void main(String[] args) {
try {
Test b = new Test();
System.out.println("WIN!");
} catch (Exception ex) {
System.out.println("LOSE!");
}
}
}❤2