This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes hi i need help..please help me... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hi i need help..please help me..." Watch "hi i need help..please help me..." New topic
Author

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

ann chua
Greenhorn

Joined: Jul 06, 2009
Posts: 2
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

Joined: Mar 19, 2008
Posts: 231
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

Joined: Jan 28, 2008
Posts: 5575

if you want output 14 then space is important here
Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
seetharaman venkatasamy wrote:if you want output 14 then space is important here


seetharaman venkatasamy is right !
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11167
    
  16

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

Joined: Mar 19, 2008
Posts: 231
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

Joined: Jul 26, 2007
Posts: 10171
    
    8

Ann,
Welcome to the Ranch.
Next time, while posting, please use a meaningful subject line


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
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


Joanne
ann chua
Greenhorn

Joined: Jul 06, 2009
Posts: 2
thank you for the help. oh, ok sorry. i will next time.

thank you.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: hi i need help..please help me...
 
Similar Threads
Regarding Threads
Increment Test
JQ+ Operator Question!!
increment operator
Marcus Exam 3 Qn# 54