Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Arrays

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Arrays

    I am writing a public instance method called writeCharacter() which takes a single argument
    of type char called aCharacter and returns no result. The method invokes the getCharacter() method
    on the DisplayFont class with aCharacter as its argument. The getCharacter() returns a two-dimensional
    array of type boolean which has x and y dimensions.
    I would like to assign the array to a local variable called alpha.

    The question is how do I code this with correct syntax into my method writeCharacter(char aCharacter)

     
    /* instance method */
     
    	/**
    	 *    
    	 */
    	public void writeCharacter(char aCharacter)
     
      {
         DisplayFont.getCharacter(aCharacter);
     
      }


    Thanks a million,

    av8
    Last edited by helloworld922; June 25th, 2011 at 01:19 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Arrays

    Simply declare the array and assign the return result of getCharacter to that variable. There's no need to pre-determine the dimensions (that's determined by getCharacter when it first allocated the array).

    public void writeCharacter(char aCharacter)
     
      {
         boolean alpha[][] = DisplayFont.getCharacter(aCharacter);
     
      }

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Arrays

    Have you tried anything yet?
    Can you post the declaration for the getCharacter() method?
    Define a two dimension array:
    <type>[][] twoDim; // define a two dimensional array of type <type> (replace <type> with the type
    Then you can assign what is returned by getCharacter() to the twoDim variable.

Similar Threads

  1. 3 Arrays
    By D3158 in forum Collections and Generics
    Replies: 27
    Last Post: June 16th, 2011, 11:10 AM
  2. 2d arrays help
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 27th, 2010, 05:27 PM
  3. arrays
    By dwamalwa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2010, 01:44 AM
  4. Arrays
    By mlan in forum Java Theory & Questions
    Replies: 2
    Last Post: February 26th, 2010, 10:23 AM
  5. 2d Arrays
    By mgutierrez19 in forum Collections and Generics
    Replies: 5
    Last Post: October 27th, 2009, 04:08 PM