+ 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