Ask Question
29 October, 22:29

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

+2
Answers (1)
  1. 30 October, 02:17
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers