From 8c2d420b8535acc4b88aadebb20baf090eb8f9c5 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 8 May 2023 10:04:58 -0600 Subject: [PATCH] Day 1 break 2 --- Questions.txt | 63 +++++++++++++++++++++++++++++++- src/main/java/textblock/Ex1.java | 18 +++++++++ src/main/java/usingvar/Ex1.java | 14 +++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/main/java/textblock/Ex1.java diff --git a/Questions.txt b/Questions.txt index 1a838a0..88fc4de 100644 --- a/Questions.txt +++ b/Questions.txt @@ -37,4 +37,65 @@ D) void doStuff() { E) void doStuff() { var x = { 1, 2, 3 }; - } \ No newline at end of file + } + +Q) Given: +var x = true ? "99" : 99; + +What is the type of x? +A) none, it's fails to compile +B) int +C) String +D) Object +E) none of the above + +Q) Given: + + public static void main(String[] args) { + final StringBuilder sb = new StringBuilder("Hello"); + sb.append(" world!"); + System.out.println(sb); + } + + What is the result? + A) Compilation fails + B) Hello + C) Hello world! + D) Exception at runtime + +Q) Given: + +String message = """Hello\ +Java 17 World!"""; +System.out.println(message + "XXX"); + +What is the result? +A) Compilation fails +B) Exception at runtime +C) Hello + Java 17 World!XXX +D) Hello Java 17 World!XXX +E) Hello Java 17 World! + XXX + +Q) Given: + String message = """ + Hello + Java 17 World!"""; + System.out.println(message + "XXX"); + +What is the result? +A) +Hello +Java 17 World!XXX +B) +Hello + Java 17 World!XXX +C) +Hello +Java 17 World! +XXX +D) + Hello + Java 17 World! +XXX diff --git a/src/main/java/textblock/Ex1.java b/src/main/java/textblock/Ex1.java new file mode 100644 index 0000000..77098be --- /dev/null +++ b/src/main/java/textblock/Ex1.java @@ -0,0 +1,18 @@ +package textblock; + +public class Ex1 { + public static void main(String[] args) { + String message = """ +Hello\ +Java 17 World!"""; + System.out.println("XXX" + message + "XXX"); + + System.out.println("------------"); + String message2 = """ + ""\"""\"""Hello", he said + Java 17 World! + """; + System.out.println(message2 + "XXX"); + + } +} diff --git a/src/main/java/usingvar/Ex1.java b/src/main/java/usingvar/Ex1.java index ec64691..f119545 100644 --- a/src/main/java/usingvar/Ex1.java +++ b/src/main/java/usingvar/Ex1.java @@ -31,6 +31,18 @@ public static void main(String[] args) throws Throwable { // try (FileReader in = new FileReader("")) { // } catch (var ex) { } + +// nope, can't change base type during autoboxing +// Long i = 2_000_000_000; + + var x = true ? "99" : 99; + +// Integer in = null; // also for String :) +// in.compareTo... and others + +// int goto; +// var var = "var"; + int var = 99; } // void doStuff() { @@ -46,3 +58,5 @@ public static void main(String[] args) throws Throwable { // showStuff(new String[]{"a", "b"}); // } } + +//class var {} \ No newline at end of file