class C{
public static void main(String a[]) {
int i1=9;
int i2;
if(i1>3) {
i2=8;
}
System.out.println(i2);
}}
aditya027
0
Newbie Poster
Recommended Answers
Jump to PostPosting the error message that you get, would help a lot.
Jump to PostWhat do YOU think is wrong with it? Have you compiled it? Have you executed it? Have you tried executing it with a different value for i1 (eg 0)?
Jump to PostYou are trying to print out a variable(i2) which is possibly uninitialized (depends on rutime, i2 won't be initialized if i1 < 3). Either provide an initial value for i2 or write an else statement which takes care of the same.
Jump to PostHey....
while declaring any arguments in main()
you have to initialse that variable with any value..
Otherwise you have to face the ERROR called ---- VARIABLE MIGHT NOT HAVE BEEN INITIALISED...
Jump to Postafter declaring the variable 'i as final' the code runs just fine
Your code doesn't show a variable: 'i'?
All 19 Replies
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
akshay357
0
Newbie Poster
aditya027
0
Newbie Poster
aditya027
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
aditya shikhar
0
Newbie Poster
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
NormR1
563
Posting Sage
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
NormR1
563
Posting Sage
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
aditya shikhar
0
Newbie Poster
jon.kiparsky
326
Posting Virtuoso
WargRider
10
Junior Poster
aditya027
0
Newbie Poster
WargRider
10
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.