Ask Question
1 April, 12:14

After the execution of the following code, what will be the value of num if the input values are 0 3? (Assume that console is a Scanner object initialized to the standard input device.)

int num = console. nextInt ();

if (num > 0)

num = num + 13;

else

if (num > = 3)

num = num + 15;

a) 0

b) 3

c) 13

d) 15

+3
Answers (1)
  1. 1 April, 16:11
    0
    Option a: 0

    Explanation:

    Scanner is a Java class used to read a standard input from user. However, the Scanner object nextInt () method can only read an integer per time. If we input 0 3, the first integer will be taken which is 0.

    Since the num = 0, the if block will be ignored. Instead, the else block of codes will run. In the else block, the line num = num + 15 will be skipped as well because the if condition is not met. At the end, the num will remain 0.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “After the execution of the following code, what will be the value of num if the input values are 0 3? (Assume that console is a Scanner ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers