why this code only displays four zeros ?????
public class VargjetUshtrimi2 {
public static void main (String a []) {
int r[] = new int[11];
for (int i = 1 ;i < 10; i++)
{System.out.println( r[i] );}
}
}
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.
why this code only displays four zeros ?????
public class VargjetUshtrimi2 {
public static void main (String a []) {
int r[] = new int[11];
for (int i = 1 ;i < 10; i++)
{System.out.println( r[i] );}
}
}
String args[], not a[]. You are not initializing an array within the parameters.
Moreover, your array r is uninitialized. Initialize it with numbers before printing it.
The code works good and its not problem with (String a[]) but i dont know why when i run it only displays four zeros like this
0
0
0
0
Please post your code correctly per this link.
Because Your array stores "garbage value" for now. You haven't initialized it with numbers, you have just declared it. So it prints 0 as default.
@Abhilash
There are no requirements for the name of the String array. a is as good as args.String args[], not a[].
I prefer the array notation like this: String[] args
If you don't understand my answer, don't ignore it, ask a question.
Thanks Abhilisha
I also don't understand why that code only shows 4 zeros. It should show 9 zeros!!!why this code only displays four zeros ?????
If you don't understand my answer, don't ignore it, ask a question.
Actually, by garbage value I means the array does no store anything for now (i.e. it hasn't been initialized in the program). Although java initializes it automatically, but this method shouldn't be used.
I don't get the question because it does display 9 zeroes. I copied it and ran it. It works!