1. What is the output of the following Java code ? int a=3, b=-3, c=0; if (a > = c){ if (b != -3) System.out.println("X"); System.out.println("Z"); } System.out.println("Y"); else else Z X 2. The Java expression: (3+2)*4 Can be also written as: (3*4+2*4) Incorrect Correct 3. The following Boolean expression: (x || !x) Will always give : true false
H3-(1) Basic Java Syntax. (self learning quiz)
Introduction to Java
-You can add //comments for a better understanding. explanation throw
-Explanation through with answers.
-Please answer without abbreviation.
-Make it clean and clear typing/writing.
Thank you.
![1. What is the output of the following Java code ?
int a=3, b=-3, c=0;
if (a >= c){
if (b != -3)
System.out.println("X");
System.out.println("Z"); }
System.out.println("Y");
else
else
Y
Z
X
2. The Java expression:
(3+2)*4
Can be also written as:
(3*4+2*4)
Incorrect
3. The following Boolean expression:
Correct
(x || !x)
Will always give :
true
4. What is the output of the following Java code ?
int x=0;
x=(4-2*3)+5%4-2;
System.out.println(x);
false
5. The following Boolean expression:
-1
!(!(!(!x)))
Is equivalent to:
6. The following Boolean expression :
!x
!(X<5)
else
Is most equivalent to:
else
x!=5
x==5
x>=5
7. Given the following Java code, what will be the final value of variable k ?
int k=4, j;
k--;
if (k%5==0)
x>5
j=9;
else if (k%7==0)
j=28;
else
j=7;
switch (k) {
case 9:
--k;
break;
case 28:
++k;
break;
default:
k=k*2;
break;}
8. What is the output of the following Java code ?
int a=4, b=3, c=2;
System.out.println("The result is = "+(++a*(c+8)/5-4*b--));
6
The result is = 0
The result is = -4
The result is = -2
9. What is the output of the following Java code ?
int h=2, f=0, m = -2;
The result is = 2
if ((h >= m ^ h<m) && !(f != 0))
System.out.println("H");
System.out.println("L");
H
10. What is the output of the following Java code ?
int year=2008;
if ((year % 4 = = 0 && year % 100 != 0) || (year % 400 == 0))
System.out.println(year+" is a leap year !");
System.out.println(year+" is NOT a leap year !");
2008 is a leap year !
2008 is NOT a leap year !
11. What is the output of the following Java code?
int num=0;
num--;
System.out.println(num*-1);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F14e2a5f3-ac75-428e-bb14-abba01aeee13%2Fad960caf-d9a4-46ec-a076-c19946d85b51%2F1h9txim_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
As per our guidelines, we are supposed to answer the first 3 questions of multiple-choice questions, please repost other questions as separate questions.
We are given Java code's snippets and based on the logic we are supposed to find out the output generated by them.
I have first explained the whole logic behind each output like what's the output and then why we got this particular output etc. Then I have also attached screenshots of the output code to verify the solution.
I hope the explanations help you understand the logic behind the codes given.
Step by step
Solved in 5 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)