+ 6

What is the difference between --y and y--

What is the solution of this 🤔 int x =15 ; int y =5; System.out.println (x++ % --y );

11th Jan 2020, 1:39 PM
Nada Rizk
Nada Rizk - avatar
11 ответов
+ 11
--y means decreasing y before using, y-- means decreasing y after using. Example : int x=5; int y=5; System.out.print(--x +" " + y--); writes 4 5 So int x=15; int y=5; System.out.println(x++ % --y) calculates 15%4=3 writes 3.
12th Jan 2020, 6:34 AM
Софья Мальцева
Софья Мальцева - avatar
+ 5
15 % 4 = 3
10th Mar 2020, 6:42 AM
Ketul Patel
Ketul Patel - avatar
+ 3
15 % 4 = 3 This is prefix and postfix operators.
11th Jan 2020, 2:11 PM
Oleksii Novikov
Oleksii Novikov - avatar
+ 3
Judging by the fact that you have successfully completed the study of three programming languages, I thought that you should be well aware of this topic and therefore did not comment on your answer in detail, but since you re-ask for my clarifications, here is a link to a previously asked question, where is my answer:☺ https://www.sololearn.com/Discuss/1805551/?ref=app https://www.sololearn.com/learn/Java/2141/
11th Jan 2020, 9:46 PM
Solo
Solo - avatar
+ 3
--y : y is decremented,then assigned back to y y-- : y is assigned first,then it is decremented In the line of code, At x++, x is assigned 15,then only it is incremented. At --y, y is decremented,and y is assigned 4. So 15%4 =3.
13th Jan 2020, 12:43 AM
Joey Lim
Joey Lim - avatar
+ 2
Out 3
11th Jan 2020, 1:44 PM
Solo
Solo - avatar
+ 2
How ? Vasiliy
11th Jan 2020, 1:58 PM
Nada Rizk
Nada Rizk - avatar
+ 2
This mean x++ return the same value but if it's ++× It return (16) Right Alex Novikov
11th Jan 2020, 2:15 PM
Nada Rizk
Nada Rizk - avatar
11th Jan 2020, 4:42 PM
Jayakrishna 🇮🇳
+ 2
The prefix increment or decrement makes the action first like in --y means you reduce the value by one then assign it to the variable y, but the opposite is in x++ it assigns the value of x and after that increments it by one.
13th Jan 2020, 12:26 AM
‎محمد عبدالكريم ابوخشيم‎
‎محمد عبدالكريم ابوخشيم‎ - avatar
+ 1
But it's not increment'd if its x++ % --y Whoever created this code probably created common core math. Makes absolutely no sense for x=15 + 1 but the 1 disappears unless it's 1 + x
13th Jan 2020, 6:12 AM
Thomas Sixberry
Thomas Sixberry - avatar