CopyArrayNoGood - original array //but it does becasue the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Program that attempts to copy data array into prices array using a shallow copy / import java.util.Scanner; i public class CopyArrayNoGood { public static void main (String [] args) { double [] data = {1.25, 4.95, 5.00, .99, 10.23}; double [] prices = data; System.out.println("original array is :"); printArray(data); System.out.println("copy array is :"); printArray(prices); //change 3rd element in prices array to 10.00 - this should not effect
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: original array //but it does becasue the copy was a shallow copy - copied the references not the contents prices[2] = 10.00; System.out.println("original array is :"); printArray(data); p System.out.println("copy array is :"); printArray(prices); } //Method to print contents of an array public static void printArray(double arr) { for(int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }...
View Full Document

This note was uploaded on 06/07/2010 for the course CS 201 taught by Professor Staff during the Spring '08 term at Iona.

Ask a homework question - tutors are online