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 2 of 2

Thread: Can I pass character array to new method?

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can I pass character array to new method?

    Hello all. This is my first post! I am trying to teach myself a little Java. I have no coding experince.

    Anyway, is there a way to pass a character array to a new method? I am trying to create a "virtual 3d box." After the box has been created I want the user to enter a number which will change the box dimensions. (One Number will change both the height, width, and length). How do I pass my "this.box" character array to my growBox method? The character array are the dimensions of the box which I set as [1][1][1. After the user inserts the factor he wants to grow the box by I want to return the new dimensions to the main method. Your help would greatly be appreciated.

    public class Box {

    private char [][][] box;

    public void main(String[] args) {
    this.box= new char [1][1][1];
    }

    public int[][][] growBox(int height, int width, int length){
    Scanner boxChange1 = new Scanner(System.in);
    System.out.println("By which factor would you like to grow the box?");
    int box = boxChange1.nextInt(); //Is this right?
    return box
    }
    }


  2. #2
    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: Can I pass character array to new method?

    a way to pass a character array to a new method?
    You pass an array the same as you pass any other variable to a method.
    growBox(box,...); // pass the box array to the growBox method

    int[][] growBox(char[][][] anArray, ....) {


    Is this right?
    Compile it and execute it and see what happens.

Similar Threads

  1. Can you pass parameters from one method into another method?
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 2
    Last Post: April 14th, 2011, 07:46 AM
  2. Reverse character using void method
    By bgwilf in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 8th, 2010, 07:25 AM
  3. how to pass a variable from a method to another
    By amr in forum Java Theory & Questions
    Replies: 1
    Last Post: November 20th, 2010, 10:32 PM
  4. Can't pass to the other method
    By mingming8888 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 27th, 2010, 09:44 AM
  5. How do you pass an Array as a Parameter?
    By Arius in forum Java Theory & Questions
    Replies: 1
    Last Post: January 23rd, 2010, 09:36 PM