Ask Question
4 January, 15:11

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

+1
Answers (1)
  1. 4 January, 15:24
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers