Putting the line of code
y = array;
will cause the y to point to same piece of memory pointed by array, array is declared of size 100
and the for loop starts from 100, the value y.length is 100, therefore it won't go in the loop
 
In the case when u move y=array below the loop, the size of y is 200 therefore it loops
 
----- Original Message -----
To: jdjlist
Sent: Saturday, February 08, 2003 8:52 AM
Subject: [jdjlist] Fw: another different problem I don't quite understand ????

 
Dear list,
 
There is one other problem I am getting which I don't quite understand (a different one to the one I was asking about before)
 
:The program is also a short one.
 
 
 
=======================================================================
=======================================================================
 
 
public class Tute9Q1 {
 
 
public static void main (String [] args)
{
 
double [] array = new double[100];
double [] y     = new double[200];
 
double value = 7.5;
 
for(int p = 0; p < 100; p++)
{
  array[p] = value;
value += 2.5;
 
 
}//end of for loop
 
 
for (int p = 0; p < array.length; p++)
{
  y[p] = array[p];
 
}//End of for loop
 
 
y = array;
//putting the above assignment in, causes the loop below not to work ie
//when I run the program, the loop below doesnt produce any output.
//If I put the above line below the loop below, then it works
// I don't understand.
 
 
for (int r = 100; r < y.length; r++)
{
 
 System.out.print("y[r]>" + y[r] + "   ");
 
} // end of for loop
 
 
System.out.println();
System.out.println();
System.out.print("y 51st element:" + y[50]);
 
 
}//End of main method
}// End of class
 
 
========================================================================
========================================================================
 
The problem is when I put in the assignment statement ---
y = array;
 
that causes the loop below the assignment not to produce any output.
 
And I don't quite understand why ?
 
Am I correct in suggesting what the statement y = array is actually about ? That y then gets the same reference
as array ? That by using "y" and "array" we are referring to the reference to the array object of these 2 arrays ?
 
But I don't understand why by putting the assignment statement y = array ,where it is, causes the loop below it not to work ?
 
Can you suggest what is wrong ?
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to