*1. Answer to 1st question
*The number "0" is printed for the second for loop & as the 2nd for loop
starts the value that is to be printed i.e. zero is printed in that line
where "12345678910" is also printed.
*2. Answer to 2nd question
*Firstly, the 2nd for loop prints the array value's 9 times i.e. 9 zero's
not 8. In the program that "x" is declared as an array of size of 10. So as
the for loop is written like this
- for (int c=1; c < x.length; c++)
{
System.out.println(x[c]);
}
so we have the desired output. But if we write the for loop like this
- for (int c=1; c <= x.length; c++)
{
System.out.println(x[c]);
}
we can have 10 zero's instead of 9.
*NOTE-See the term "length" that is being written along with the variable is
used to determine the size of the array dynamically. If still in doubt write
2 separate programs i.e. 1st for loop & 2nd for loop like this-
*
- *Program 1*
* class ArraySample
{
public static void main(String[] args)
{
int [ ]ArrVar1 = {1,2,3,4,5,6,7,8,9,10};
for (int a=0; a < ArrVar1.length; a++)
{
System.out.print(ArrVar1[a]);
}
}
}
*
- *Program 2*
*class ArraySample2
{
public static void main(String[] args)
{
final int A = 10000;
int []x = new int [A];
x = new int [10];
for (int c=1; c < x.length; c++)
{
System.out.println(x[c]);
}
}
}*
Regards,
Varun Kumar Sahu
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---