-
returning double array
i am trying to create something that will show the center Y positions on a label depending on the amount of lines needed and the text height. I have all the equations and such but is there a way to return a double array. this is what i have now:
Code:
import java.util.Scanner;
public class XYCalc
{
public static double[] calcY(double lines, double textHeight, double labelHeight)
{
double k = labelHeight / lines;
double l = k / 2;
double y = l - (textHeight / 2);
double o[] = {2, 9};
return o;
}
public static void main(String [] args)
{
double lines;
double textHeight;
double labelHeight;
Scanner input = new Scanner(System.in);
System.out.println("Amount of lines: ");
lines = input.nextDouble();
System.out.println("Height of text: ");
textHeight = input.nextDouble();
System.out.println("Height of label: ");
labelHeight = input.nextDouble();
input.close();
double y[] = calcY(lines, textHeight, labelHeight);
System.out.println("Y: " + y);
}
}
and i get this:
Code:
Amount of lines:
2
Height of text:
.5
Height of label:
2
Y: [D@14318bb
Process completed.
I would like to be able to read it haha.
Thanks in adv.
-
You're getting the default toString() representation of a double array. To show the array elements, either use a for loop to iterate through the array printing as you go, or use java.util.Arrays.toString(myArray) to convert the array to String for display.
-
Thanks so much! I am fairly new to all this so I really do appreciate it.