The document contains a series of programming questions and code snippets related to Java, focusing on loops, conditionals, and mathematical expressions. It includes tasks such as predicting outputs, rewriting code, and identifying errors. The questions test knowledge of Java syntax, logic, and data types.
The document contains a series of programming questions and code snippets related to Java, focusing on loops, conditionals, and mathematical expressions. It includes tasks such as predicting outputs, rewriting code, and identifying errors. The questions test knowledge of Java syntax, logic, and data types.
int x, y; do { for (x = 1; x <= 5; x + +) { sum = sum + num; for (y = 1; y < x; y + +) { num + +; if (x == 4) } while (num < 2); break; 8. Predict the output of the following. System. out. print(y); (a) Math. pow(3.5, 3) + Math. ceil (4.2) } (b) Math. round (3.6) +Math.log (10) System. out. println(); 9. Observe the following code and write how many } times will be the loop execute? 2. What will be the output of this nested loop a = 8; structure? b = 6; int i, j; while (b ! = 0) { first: r = a% b; for (i = 10; i >= 5; i − −) { a = b; for (j = 5; j <= i; j + +) { b = r; if (i ∗ j < 40) } continue first; Systern.out.println(" "+ a); System. out. print(j); 10. Write the Java statement for the following } mathematical expression: System. out. println(); 0.02 − 3y 3 } a= x+y 3. What will be the output of the given code? 11. Give the output of the following expression, when for (int i = 0; i < 4; i + +) { a=6 for (int j = i; j >= 0; j − −) a+= + + a + a + + + a − − + a − − + − − a System. out. print(j); + + +a System. out. println(); 12. Determine the values of n and m after executing the } following code: 4. What will be the output of this code snippet? int m; int m = 3, n = 5, p = 4; int n; if (m == n && n ! = p) { m=5; System. out. println(m ∗ n); n=(5*++m)%3; System. out. println(n % p); System.out.println("n=" +n+"m=" +m ); } 13. What will be the outcome of the following if ((m ! = n) || (n == p)) { statements? System. out. println(m + n); int a=3; System. out. println(m − n); System.out.println(" "+(1+a)); } System.out.println(" "+ 1 +a); 5. The following code has some error(s). Rewrite the 14. What will be the output of the following correct code and underlining all the corrections expressions? made. (a) Math.pow(3.4, 2)+2*Math. sqrt(64) int counter = O; (b) Math.ceil(3.4)+2*Math. floor(3.4)+2 integer i = 1; num; 15. What will be the error in the following Java code? for(num = i; num >= 1; num − −) { byte b = 50; If i%num = O b = b ∗ 5O; { (a) b cannot contain value 100, limited by its range. counter = counter + 1; (b) Operator has converted b*50 into int, which } } cannot be converted to byte without casting. 6. Rewrite the following program segment using while (c) b cannot contain value 50. instead of for loop. (d) No error in this code int f = 1, i; 16. Write the Java statement for the given for(i = l; i <= 5; i + +) { mathematical expression: f ∗= i; √3𝑥 + 𝑥 2 𝑑= System. out. println(f); 𝑎+𝑏 } 17. What will be the output of following code snippet? 7. Write the values that will be stored in variables num int n = 300, a = 200; and sum after executing of following code. if(a + n ∗ 10 > 5000) int sum = 5; System. out. println("100"); else if(i == 4) { System. out. println("200"); n = 1; 18. State the values of num and chr: break; char ch - 'C'; } int num =ch+ 3; } while(i < 5); char chr = (char) num; 27. Assertion (A): Primitive data types are the data 19. Write the output of the following code in Java. types defined by the language itself. int x = 0; Reason (R): Class interface and array are the while (x <= 3) { examples of primitive data types. System. out. println(x); (a) Both Assertion and Reason are true, and Reason x = x + 1; is a correct explanation of Assertion. } (b) Both Assertion and Reason are true, but Reason 20. Rewrite the following code using while loop. is not a correct explanation of Assertion. int a = 100; (c) Assertion is true, and Reason is false. for(int b = 2; b <= 30; b = b + 5} { (d) Assertion is false, and Reason is true. System. out. println("\n" + (b + a) ); 28. Assertion (A): Class is considered a primitive data a = a − 2; type. } Reason (R): A class is a user-defined data type, 21. What will be the value of variables m and n after meaning it is created by the user. the execution of the following code? (a) Both Assertion and Reason are true, and Reason int m, n = O; is a correct explanation of Assertion. for(m = l; m <= 4; m + +) { (b) Both Assertion and Reason are true, but Reason n+= m; is not a correct explanation of Assertion. n − −; (c) Assertion is true, and Reason is false. } (d) Assertion is false, and Reason is true. 22. The following code has some error(s). Rewrite the 29. It is also referred to as a desktop or window-based correct code and underlining all the correction application. made: (a) Package (b) Java Applet float m = 6, float n = 1, p = 1; (c) Servlet (d) Stand-alone application do; 30. Read the following text and choose the correct p == p ∗ n; answer. n + +; while (n <= m) ; Abstraction is a key concept in Object-Oriented System. out. print(" " + p); } Programming (OP) that focuses on representing 23. Given the following set of identifiers. essential features while omitting unnecessary char c; byte b; background details or explanations. int I; short s; What is an abstraction? long l; float f; (a) Abstraction is more about 'What' a class can do. ldentify the data type of i ∗ l + f expression. (b) Abstraction is more about 'How' to achieve that 24. Rewrite the following program code using if-else functionality. statement: (c) It binds data and methods in a single unit. int a = 2; (d) It implements using private access modifier. switch(a) { 31. Assertion (A): The factory of object means a factory case 0: GrandTotal = O. lO ∗ BillAmt; that produces the objects. break; 32. Reason (R): Class is known as object factory case 1: GrandTotal = 0.9 ∗ BillAmt; because single class generates a lot of objects. break; (a) Both Assertion and Reason are true, and Reason case 2: GrandTotal = 0.8 ∗ BillAmt; is a correct explanation of Assertion. break; (b) Both Assertion and Reason are true, but Reason default: GrandTotal = BillAmt; is not a correct explanation of Assertion. } (c) Assertion is true, and Reason is false. 25. Determine the value of m after evaluating the (d) Assertion is false, and Reason is true. following expression when int m=12, n=3? 33. The order of the three top level elements of Java m+= lO% + +n + n + +/ 4; source file is 26. How many times the following loop will execute? (a) Import, package, class int n = 1, i = 1; (b) Package, import, class do { (c) Class, import, package n + +; (d) Any order i + +;
Unreal Engine 5 Game Development with C++ Scripting: Become a professional game developer and create fully functional, high-quality games 1st Edition Zhenyu George Li - Experience the full ebook by downloading it now