- 2
help in java
can i do -- in getNumOfChanse() like getNumOfChanse()--; ? because it's gave an error
14 odpowiedzi
+ 2
What does it mean to decrement a function?
I'm not sure what do you want to do, but let's say getNumOfChanse() is a function that returns a integer and you want to decrement the value and update it, you can do it either calling another function that already gives you decremented and update it or you subtract by one and call a function to update the value.
You can't increment or decrement a function because this doesn't work in values, only on variables, so I can't write 1++ but I can write a = 1; a++.
I hope I could help and Keep the good coding :)
+ 1
No. The ++/-- is unary operator can be applied to a variable only. Not to any constant.
getNumOfChanse() -- is works as
( getNumOfChanse() ) -- ; and the method returns a constant value : a number.
You can't apply ++/-- to a constant. It's error.
store return value of a method the apply decrementation and return value.
0
i did
puplic int des(int a)
return getNumOfChanse()--;
its gava me an error also
0
i have
public void setNofC() {
this.NofC=5 ; }
public int getNoC() {
return NofC;
then i want to call
getNofc() to do --
decremnt
0
Do this instead:
public int decrNoC() {
this.Nofc--;
return Nofc;
}
0
can i do it with calling get() ?
cuz i don want to use Notc
when i have a methode to return it
0
It depends what do you want the get() to do. But I would advise you to do the following:
public void init() {
Nofc = 5;
}
public int set(int x) {
Nofc += x;
return Nofc
}
0
Now you just need to call set(-1)
0
is the there get() ?
cuz i need it
0
public int get() {
return Nofc;
}
0
can i use it in set(int x ) ?
insted of Nofc
0
Yeah but it will be slower... If your reeeeeeaally want to use it then:
public int set(int x) {
Nofc += x;
return get();
}
I can't see the point of doing this, since you are just making the computer to do extra steps...
0
Т
0
I don't think so because it's going to be slower than the first one.