Results 1 to 3 of 3
  1. #1
    Billaguana is offline Member
    Join Date
    Jan 2011
    Posts
    21
    Rep Power
    0

    Default 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:
    Java 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:
    Java 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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    Billaguana is offline Member
    Join Date
    Jan 2011
    Posts
    21
    Rep Power
    0

    Default

    Thanks so much! I am fairly new to all this so I really do appreciate it.

Similar Threads

  1. Problem returning Array values Please help
    By drgnfire25 in forum New To Java
    Replies: 4
    Last Post: 01-12-2011, 01:53 AM
  2. returning array
    By aizen92 in forum New To Java
    Replies: 4
    Last Post: 01-08-2011, 04:10 PM
  3. Syntax error when returning an array
    By wantakill in forum New To Java
    Replies: 2
    Last Post: 09-03-2010, 07:39 PM
  4. Returning An Array
    By elektronika in forum New To Java
    Replies: 2
    Last Post: 12-07-2009, 04:43 PM
  5. Returning array problem.
    By Chase in forum New To Java
    Replies: 4
    Last Post: 10-21-2008, 10:07 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •