Computer Science, asked by rajvirmohit, 7 months ago

What is the output of java codes snippet
short k=1;
k+=2;
System.out.print(k);

Answers

Answered by adityabatmanpratap
3

Answer:

the answer is 3

Explanation:

initial value of k is 1

value of k+=2 is 3

hence new value of k is 3

Answered by Syamkumarr
0

Answer:

The output will be 3

Explanation:

According to the question,

'short' is a keyword that stores the value 1 (here)

k + = 2 has a unary operator .

Therefore, the statement means k = k + 2

Method used:

Dry run - Run the program using the input

k = 1

k+ = 2

=> k = k + 2

       = 1 + 2

       = 3

Since the final value of k is 3 , the output will be 3

Similar questions