Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hi i need help..please help me...

 
ann chua
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a problem also using the post increment in java. i have this code k=j+++i; where k=0, j=3 and i=10. its answer is 13, how can i make the answer into 14 using the post increment?.

please help.
 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ann chua wrote: how can i make the answer into 14 using the post increment?.

please help.


just use k = i+j++;


It would give desired output !

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want output 14 then space is important here
 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:if you want output 14 then space is important here


seetharaman venkatasamy is right !
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashish Tiwari wrote:just use k = i+j++;
It would give desired output !

Not according to my tests:


C:\slop>java Test
k is 13
k is 13

C:\slop>


can you do this:

j++;
k = k + i;

or this:

k = j + i;
k++;

 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:
Ashish Tiwari wrote:just use k = i+j++;
It would give desired output !

Not according to my tests:


C:\slop>java Test
k is 13
k is 13

C:\slop>


can you do this:

j++;
k = k + i;

or this:

k = j + i;
k++;




Sorry i just forget to comment the line .In fact i was trying something like



It would give the correct output



 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ann,
Welcome to the Ranch.
Next time, while posting, please use a meaningful subject line
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashish Tiwari wrote:
seetharaman venkatasamy wrote:if you want output 14 then space is important here


seetharaman venkatasamy is right !


Except for the fact that the question asked how to do it using the post increment
 
ann chua
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the help. oh, ok sorry. i will next time.

thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic