Using Java, answer the following What will be the O/P of these codes: int a = 10
ID: 3809753 • Letter: U
Question
Using Java, answer the following
What will be the O/P of these codes: int a = 10 int b = 5; int c = 0, d = 0, e = 0; c = a % b; d = a / b e = a + b + c + d; System.out.println (a = + a + b = + b + c = + c + d = + d + e = + e); //Line(1) thru Line(5) System.out.println (a = + a + , b = + b + , c = + c + , d = + d + , e = + e); //Line(6) What O/P is produced by the following code? int time = 2, tide = 3; if (time + tide > 6) System.out.println(Time and tide wait for no one.); else System.out.println(Time and tide wait for me.) Consider the following fragment of code: int x = 4; //initial value of x if (x > 5) System.out.println(A); else if (xExplanation / Answer
10. What will be the O/P of these codes:
int a = 10; //declares and sets a to 10
int b = 5; //declares and sets b to 5
int c = 0, d = 0, e = 0; //declares c, d, e and set them to 0
c = a % b; //the remainder of a/b is set to c, c will be 0
d = a / b; //the quotient of a/b is set to d, d will be 2
e = a + b + c + d; //a + b + c + d is set to e, d will be (10+5+0+2) = 17
//prints values a, b, c, d, e each in a separate line
System.out.println("a = " + a + " b = " + b + " c = " + c + " d = " + d + " e = " +e );
//prints values a,b,c,d,e in a single line each separated by commas
System.out.println("a = " + a + ", b = "+ b + ", c = " + c + ", d = " + d + ", e = " +e);
Answer: Line(1) a = 10 Line(2) b = 5 Line(3) c = 0 Line(4) d = 2 Line(5) e = 17
Line(6) a = 10, b = 5, c = 0, d = 2, e = 17
11. What O/P is produced by the following code?
int time = 2, tide = 3;
if (time + tide > 6) System.out.println("Time and tide wait for no one.");
else System.out.println("Time and tide wait for me.");
Ans: Time and tide wait for me.
(As time = 2 and tide = 3, hence time + tide will be 5, the condition time + tide > 6 fails hence the else part will be executed and prints Time and tide wait for me.)
12. Consider the following fragment of code:
int x = 4; //initial value of x
if (x > 5) System.out.println("A");
else if (x < 10) System.out.println("B");
else System.out.println("C");
What is displayed if (a) x = 4; (b) x = 5; (c) x = 6 (d) x =9
Ans: (a) B (b) B (c) A (d) A
(In the above code fragment we are using an if- else structure, in an if-else, if the condition in the if is satisfied the rest of the else cases will be skipped, if the condition in the if is not satisfied then the else part will be executed.
In the above in (a) we have x = 4 the condition x > 5 fails, hence moves to else part, in else we again had an if where the condition is x < 10 as 4 < 10 is true, the condition is satisfied and print B.
In case (b) we have x = 5 the condition x > 5 fails, hence moves to else part, in else we again had an if where the condition is x < 10 as 5 < 10 is true, the condition is satisfied and prints B.
In case (c) we have x = 6 the condition x > 5 and prints A the rest of the statements are skipped.
In case (d) we have x = 9 the condition x > 5 and prints A the rest of the statements are skipped.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.