public int getPriority(){
int i=0;
return i++;
}
this method is called in another file, i want incremented value of i and not 0 when everytime this function is called.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
public int getPriority(){
int i=0;
return i++;
}
this method is called in another file, i want incremented value of i and not 0 when everytime this function is called.
Check the functionality of postincrement and preincrement
return ++i;
will work
The variable i is local to the method: getPriority() and will always start with the value assigned in the method., i want incremented value of i
Can you explain what you want that method to do? The way it is coded it will always return the same value.
If you don't understand my answer, don't ignore it, ask a question.
[QUOTE=Norm;98940]The variable i is local to the method: getPriority() and will always start with the value assigned in the method.
Can you explain what you want that method to do? The way it is coded it will always return the same value
[Quote= shachee:] like i want output as 1 2 3 4 etc that is incremented value.. but this program will return always 1. so by session management or making i static , something like dat we can do dat thing...
--- Update ---
i want the output of that program as 1 2 3 4.. etc and not as 1 always...
with ++i will it work?
If you want the value of i to be remembered from one call to the next as it is changed, then i must be defined outside of any method as a class variable.
If you don't understand my answer, don't ignore it, ask a question.
ya i want that only.... thnx bt what will be the code for that
Are you asking how to define a class variable?
Define the variable in the class, not in a method.
If you don't understand my answer, don't ignore it, ask a question.
na not that... il check the previous thng
Sorry, I have no idea what you are saying.
If you don't understand my answer, don't ignore it, ask a question.