What is the correct output of System.out.println((10 + 3) , \" Hello\");?
Anonymous Quiz
19%
a) 13 Hello
3%
b) 10 3 Hello
0%
10 + 3 Hello
0%
c) 10 + 3 Hello
78%
d) Error
What is the correct output of System.out.println(10 + 3 + " Hello");?
Anonymous Quiz
58%
a) 13 Hello
19%
b) 10 3 Hello
3%
c) 10 + 3 Hello
19%
d) Error
Forwarded from < Ace Coding /> π
Mosh-cheat-sheets.zip
7.1 MB
π Cheat Sheets by Mosh π
Quick reference for Java, Python, SQL, and Git! π
βοΈ Java Cheat Sheet
π Python Cheat Sheet
π SQL Cheat Sheet
π» Git Cheat Sheet
Stay tuned for more! π₯
ππ @AceCoding Presents! ππ
#Java #Python #SQL #Git #CheatSheet
Quick reference for Java, Python, SQL, and Git! π
βοΈ Java Cheat Sheet
π Python Cheat Sheet
π SQL Cheat Sheet
π» Git Cheat Sheet
Stay tuned for more! π₯
ππ @AceCoding Presents! ππ
#Java #Python #SQL #Git #CheatSheet
Forwarded from < Ace Coding /> π
if (10 > 5)
int sum = 10 + 5;
System.out.println(sum);
Forwarded from < Ace Coding /> π
Whatβs wrong with the above snippet of code?
Anonymous Quiz
40%
a. Perfectly fine
14%
b. Sum is not printed
21%
c. Runtime error
24%
d. Compilation error
Forwarded from < Ace Coding /> π
Predict the output:
int i = 0;
while (++i < 5);
cout << "i: " << i << endl;
Forwarded from < Ace Coding /> π
Choose your answer for the above code.
Anonymous Quiz
31%
π
°οΈ i: 4
21%
π
±οΈ i: 5
18%
π
ΎοΈ i: 6
18%
β Infinite loop
13%
β Compilation error
Forwarded from < Ace Coding /> π
Predict the output:
int x = 5;
int y = 10;
(x > y ? x : y) = 50;
cout << "x: " << x << ", y: " << y << endl;
Forwarded from < Ace Coding /> π
Choose your answer for the above.
Anonymous Quiz
4%
π
°οΈ x: 50, y: 50
4%
π
±οΈ x: 10, y: 50
65%
π
ΎοΈ x: 5, y: 50
19%
β Undefined behavior
8%
β Compilation error
Forwarded from < Ace Coding /> π
Predict the output:
int a = (3, 4, 1, 2);
cout << a ;
Forwarded from < Ace Coding /> π
choose your answer for the above.
Anonymous Quiz
24%
π
°οΈ [3, 4, 1, 2]
0%
π
±οΈ [4, 2]
0%
π
ΎοΈ [3, 1]
6%
4
6%
2
12%
3
0%
1
18%
β Undefined behavior
35%
β Compilation error
Forwarded from < Ace Coding /> π
π Types of Errors in a Program: π₯β‘οΈπ
ππ @AceCoding Presents! ππ
π₯ Compilation Error: (Cannot compile, cannot run)
Occurs when the code has syntax issues, preventing it from being compiled. Common examples include missing semicolons, mismatched parentheses, or undeclared variables.
Example: int x = ;
β‘οΈ Runtime Error: (Compiles but cannot run, compilation comes before code execution or running)
Happens while the program is running. It usually occurs due to illegal operations like division by zero, accessing invalid memory, or infinite loops.
Example: int x = 5 / 0;
π Logical Error: (Code compiles and runs but won't result a correct output)
Occurs when the code runs without crashing, but it produces incorrect results due to flawed logic or assumptions. It can be tricky to spot as the program compiles and runs fine.
Example: int a = 5; int b = 2; cout << a - b; (Expecting multiplication but using subtraction)
ππ @AceCoding Presents! ππ
π1
Forwarded from < Ace Coding /> π
Predict the output of the following code snippets! π€
π Code Snippets: ```java String input = new String("hello"); System.out.println(input == "hello"); String input = "hello"; System.out.println(input == "hello"); ```
π Code Snippets: ```java String input = new String("hello"); System.out.println(input == "hello"); String input = "hello"; System.out.println(input == "hello"); ```
Anonymous Quiz
9%
A) True, False
45%
B) False, True
36%
C) True, True
9%
D) False, False
Forwarded from < Ace Coding /> π
πFor the above question
String input = new String("hello");
System.out.println(input == "hello");
String input = "hello";
System.out.println(input == "hello");Forwarded from < Ace Coding /> π
πΉHow can you correctly compare the contents of two strings in Java?
Anonymous Quiz
4%
A) string1 == string2
58%
B) string1.equals(string2)
4%
C) string1 != string2
0%
D) string1.compareTo(string2) == 0
35%
E) ALL
Forwarded from < Ace Coding /> π
πΉ When comparing strings in Java, what does the method compareTo() return?
Anonymous Quiz
44%
A) A boolean value (true or false)
33%
B) An integer value indicating the difference between the strings
11%
C) A string with a comparison message
11%
D) A String object with the lexicographical order of both strings
Forwarded from < Ace Coding /> π
In Java string literals (like "hello") are automatically stored in a special memory region called the string pool. When we use a string literal directly in your code, the JVM checks if that string already exists in the string pool. If it does, it reuses the same reference (i.e., the same object). If it doesn't, it adds the string to the pool.
What Happens When You Use new String()?
If you create a string using the new String() constructor, you explicitly create a new object in memory, even if the content of the string is the same.
In this case, "hello" in the string pool and the new String("hello") object are not the same object in memory, so == will return false.
ππ @AceCoding Presents! ππ
String input = "hello";
System.out.println(input == "hello"); // True
What Happens When You Use new String()?
If you create a string using the new String() constructor, you explicitly create a new object in memory, even if the content of the string is the same.
String input = new String("hello");
System.out.println(input == "hello"); // falseIn this case, "hello" in the string pool and the new String("hello") object are not the same object in memory, so == will return false.
ππ @AceCoding Presents! ππ