timNorth timNorth - 1 year ago 99
Java Question

Array and methods in java programming

In the following code I have tried to do the following

1) a String array called destinations with the names of the possible destination cities that the airline will fly to

2) to use an int array called pointCosts, that consists of the number of points it will cost customers to fly to those corresponding cities.

right now I am just trying to work on the second array pointCosts. I have used the method getMinValue to try and calculate the min value of points in the array pointCosts

Here is my code so far

public class LowFlights
public static void main( String[] args )
String[] destinations = {"Toronto", "Winnipeg", "London","Ottawa", "Miami"} ;
int[] pointCosts = {75, 90, 110, 75, 95, 95} ;
System.out.println("Lowest Point Cost: " + pointCosts) ;
public static int getMinValue(int[] numbers)
int minValue = numbers[0] ;
for(int i = 1 ; i < numbers.length; i++)
if(numbers[i] < minValue)
minValue = numbers[i] ;
return minValue;

this code should give the following output:

Lowest Point Cost: 75

however for some reason I am getting:

Lowest Point Cost: [I@286094d

Answer Source

Because you are printing the array. Try this:

int[] pointCosts = {75, 90, 110, 75, 95, 95} ;
int minCost =  getMinValue(pointCosts);    //Your function returns int value
System.out.println("Lowest Point Cost: " + minCost) ;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download