Java: Expression Evaluation Questions! Trivia Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Suma
S
Suma
Community Contributor
Quizzes Created: 4 | Total Attempts: 6,018
Questions: 11 | Attempts: 439

SettingsSettingsSettings
Java: Expression Evaluation Questions! Trivia Quiz - Quiz

This trivia quiz is made up of expression evaluation questions on Java. It is perfect for any computer geek who wants to test out how good they are when it comes to the solving problems associated with the computer language. How about you try it out and get to perfect your skills in the process? Keep an eye out for more quizzes like it!


Questions and Answers
  • 1. 

    Write the value of z after the execution of the following code : int j; int z, j=16; z = (4*j++)/3;   Hint: 1)evaluate from Left to Right 2) Prefix(++j) change and use, postfix use and change(j++) 3)Binary operations based on BODMAS rule 4) division, multiplication, and modulus whichever comes first should be performed first.  5) numerator and denominator are integers perform only integer division  151/3 = 50  6) assign the value to z.

    • A.

      21

    • B.

      20

    • C.

      19

    • D.

      17

    Correct Answer
    A. 21
    Explanation
    The code initializes the variables j and z, and assigns the value 16 to j. Then, it calculates the value of z using the expression (4*j++)/3. Since the postfix increment operator is used (j++), the value of j is first used in the expression and then incremented. Therefore, the value of j in the expression is 16, and the expression simplifies to (4*16)/3 = 64/3 = 21. Finally, the value 21 is assigned to z.

    Rate this question:

  • 2. 

    What will be the value of j and k after execution of the following code:  int j=22,k=20; if(k>=j) k=j;  j=k;

    • A.

      K=21,j=20

    • B.

      K=20, j=20

    • C.

      K=22,j=22

    Correct Answer
    B. K=20, j=20
    Explanation
    The code first checks if k is greater than or equal to j. Since k is 20 and j is 22, the condition is not true and k remains unchanged. Then, the value of k is assigned to j, so j becomes 20. Therefore, the final values are k=20 and j=20.

    Rate this question:

  • 3. 

    Write the value of P after execution of following code : int p; int  k=18; p = (6*++k)/3;

    • A.

      P=37

    • B.

      P=38

    • C.

      P=28

    Correct Answer
    B. P=38
    Explanation
    The code initializes two variables, p and k, with p being uninitialized and k being assigned the value 18. The expression (6*++k)/3 is then evaluated and the result is assigned to p. The operator ++k increments the value of k by 1 before the multiplication is performed. Therefore, the expression becomes (6*19)/3, which simplifies to 114/3 and further simplifies to 38. Therefore, the value of p after the execution of the code is 38.

    Rate this question:

  • 4. 

    What will be displayed in jTextField1 and jTextField2 after the following code is executed: int t; int s; s = 17; t = (4*s++)/2;     jTextField1.setText(" "+t); jTextField2.setText(" "+s);

    • A.

      30   // jTextField1 17  // jTextField2

    • B.

      32   // jTextField1 16  // jTextField2

    • C.

      34   // jTextField1 18  // jTextField2

    • D.

      Option 4

    Correct Answer
    C. 34   // jTextField1 18  // jTextField2
    Explanation
    After the code is executed, the value of s is incremented by 1 (s++), and then multiplied by 4. The result is divided by 2 and assigned to t. Therefore, t will have the value of 34.

    The value of s is incremented to 18 due to the post-increment operator (s++). Therefore, jTextField2 will display the value 18.

    Rate this question:

  • 5. 

    What will be displayed in jTextField1 and jTextField2 after the following code is executed: int num = 35 , num1 = 86 ; jTextField1.setText( num + num1 + " " ) ; jTextField2.setText( " " + num + num1 ) ; Hint :  As you move from left to right, on the left and right of + operator if it is a number, it will add, if anyone is a string it will concatenate

    • A.

      121   // jTextField1 3586 // jTextField2

    • B.

      120   // jTextField1 3586 // jTextField2

    • C.

      121   // jTextField1 3585 // jTextField2

    Correct Answer
    A. 121   // jTextField1 3586 // jTextField2
    Explanation
    The code first adds the values of num and num1, which are 35 and 86 respectively. The sum is then converted to a string and displayed in jTextField1.

    In jTextField2, the code concatenates the strings " " and "3586", which are the string representations of num and num1 respectively. Therefore, the final output in jTextField2 is "3586".

    Rate this question:

  • 6. 

    Given a String object named 'code' having value as “918” stored in it. What will be the result of the following? JOptionPane.showMessageDialog(null, " " +(code.length( )+ Integer.parseInt(code))); Hint : String code = "918";

    • A.

      920

    • B.

      921

    • C.

      922

    Correct Answer
    B. 921
    Explanation
    The code.length() method returns the length of the string "code", which is 3. Integer.parseInt(code) converts the string "code" into an integer value, which is 918. Adding these two values together gives us 921. Therefore, the result of the given code will be 921.

    Rate this question:

  • 7. 

    What will be the content of the jTextArea1 after executing the following code : int n = 99; jTextAreal.setText(Integer.toString(n++)); Hint : Postfix (n++) means use and change

    • A.

      99

    • B.

      100

    • C.

      98

    Correct Answer
    A. 99
    Explanation
    The content of jTextArea1 after executing the code will be 99. This is because the code uses the postfix increment operator (n++), which means that the value of n is first used in the Integer.toString() method and then incremented by 1. Therefore, the initial value of n (99) is displayed in the jTextArea1.

    Rate this question:

  • 8. 

    Int d; int c; d=15; c = (5*++d)%3+d; Hint : modulus(%) returns the remainder of the division

    • A.

      18

    • B.

      17

    • C.

      16

    Correct Answer
    A. 18
    Explanation
    The code first increments the value of d by 1 using the pre-increment operator (++d). Then it multiplies 5 with the incremented value of d, which is 16. The modulus operator (%) is used to find the remainder when dividing the result (80) by 3. The remainder is 2. Finally, the remainder (2) is added to the original value of d (15), resulting in 17. Therefore, the correct answer is 17.

    Rate this question:

  • 9. 

    Write the values of sum and x after execution of the following code : int sum, x; sum =1 7; x =1 5; sum = sum + (x++);

    • A.

      Sum = 30 x=15

    • B.

      Sum = 32 x=16

    • C.

      Sum = 31 x=15

    • D.

      Option 4

    Correct Answer
    B. Sum = 32 x=16
    Explanation
    The code initializes two variables, sum and x. It then assigns the value 17 to sum and the value 15 to x. The line sum = sum + (x++); adds the current value of x (15) to sum and then increments the value of x by 1. Therefore, the new value of sum is 32 (17 + 15) and the new value of x is 16.

    Rate this question:

  • 10. 

    Write the value that will be assigned to variable C after executing the following statement: C = 125-15*4/3-10+6;

    • A.

      100

    • B.

      101

    • C.

      99

    • D.

      Option 4

    Correct Answer
    B. 101
    Explanation
    The expression C = 125-15*4/3-10+6 can be simplified using the order of operations (PEMDAS). First, we perform the multiplication and division from left to right, so 15*4/3 equals 20. Then, we subtract 20 from 125, giving us 105. Next, we subtract 10 from 105, resulting in 95. Finally, we add 6 to 95, giving us the final value of C, which is 101.

    Rate this question:

  • 11. 

    Write the values of c and d after execution of following code: int a =1 1; int b = 12; int c; int d; c = ++b; d = a++; c++;

    • A.

      C=13 d=10

    • B.

      C=12 d=11

    • C.

      C=14 d=11

    • D.

      Option 4

    Correct Answer
    C. C=14 d=11
    Explanation
    The code initializes variables a and b with the values 11 and 12 respectively.

    The statement "c = ++b;" increments the value of b by 1 and assigns the new value (13) to c.

    The statement "d = a++;" assigns the current value of a (11) to d and then increments the value of a by 1.

    The statement "c++;" increments the value of c by 1.

    Therefore, after the execution of the code, the value of c is 14 and the value of d is 11.

    Rate this question:

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.