I am Indian
Forum Addict
- Joined
- Mar 9, 2011
- Sythe Gold
- 0
- Messages
- 448
I'm totally new to Java basics. I've had my own RSPS, and I'm good on coding that, but now I want to make something totally by me. I've a shitty problem in declaring variable.
I want to declare a variable, but I don't know how to. I just started with Java 2 days ago in my school and we've just learnt making a calculator.
I don't have to declare n2 as a text like I declared n1 & r1. Above, I've made n1 declare the value of n2. E.G.
I'm not able to express what I meant I guess, but if you get me, please reply helping me.
Thanks.
I want to declare a variable, but I don't know how to. I just started with Java 2 days ago in my school and we've just learnt making a calculator.
int n1,n2,r1,q;
n1=Integer.parseInt(cb.getText());
r1=Integer.parseInt(tw.getText());
if (n1 > 10 && n1 < 20) {
n2 = 450;
} else if (n1 > 20 && n1 < 30) {
n2 = 400;
} else if (n1 > 30 && n1 < 40) {
n2 = 350;
}
q=n2*r1; <-- error saying 'variable n2 might have not been initialized'.
I don't have to declare n2 as a text like I declared n1 & r1. Above, I've made n1 declare the value of n2. E.G.
In order to remove the error off my 'q=n2*r1;' part, I need to declare n2.if (n1 = 10) {
n2 = 400;
} else if ...........
I'm not able to express what I meant I guess, but if you get me, please reply helping me.
Thanks.

