Challenge question_Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Challenge question_Java

What is the output of this code? int a = 9%5%5; System.out.println(a); The supposed answer is "4". Could anyone explain me why? Actually, 9%5 = 4; then, 4%5=0? Or am I wrong?

2nd Apr 2018, 12:57 PM
İskender Güneş
İskender Güneş - avatar
5 Answers
+ 2
9%5=4 4%5=4 when 4 is divided by 5, the remainder is 4
2nd Apr 2018, 1:01 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 4
thankyou for your answer! So if we try to use % with a smaller and a bigger number, the output will be a smaller number, right? for example, 10%15=10?
2nd Apr 2018, 1:03 PM
İskender Güneş
İskender Güneş - avatar
+ 3
@Iskender, yes. exactly.
2nd Apr 2018, 1:04 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 3
@Iskender, You are welcome
2nd Apr 2018, 1:06 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 2
thankyou! You really helped me out ☺
2nd Apr 2018, 1:05 PM
İskender Güneş
İskender Güneş - avatar