Closed Thread
Results 1 to 6 of 6

Thread: Assignment help understanding

  1. #1
    lmc059 is offline Newbie
    Join Date
    Oct 2007
    Posts
    16
    Rep Power
    0

    Assignment help understanding

    Could anyone help with an assignment i have. I need to create an array of characters that can be any length (user defined), then converted to a string, there is a number of other tasks which i can do myself but i need to have the class in separate program from the output program i.e be able to access the methods from the main program and accessed from any other program that calls the method if that makes sense if not im in trouble haha. any help would be appreciated!!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Oct 2007
    Posts
    538
    Rep Power
    21
    Not entirely sure what you mean. Do you mean you need the methods to be in a separate class to the executing class?

    That's quite easy you just create another file "MyClass.java" and call it from within the main method. So you end up with two files, one with public static void main() and the other containing your class. Then you just instantiate that class as you would any other 'MyClass test = new MyClass();. If you only want static methods though you can do MyClass.method();.

  4. #3
    gszauer's Avatar
    gszauer is offline Programmer
    Join Date
    Nov 2007
    Location
    Florida
    Posts
    113
    Rep Power
    16
    Is this what you are looking for:

    [HIGHLIGHT="Java5"]import java.util.*;

    public class UnlimitedArray {
    static Scanner console = new Scanner(System.in);

    public static void main (String[] args){
    int arrayLength;
    char[] myArray;
    String converted;

    System.out.println("Please input array length:");
    arrayLength = console.nextInt();

    myArray = new char[arrayLength];
    for (int i = 0; i < myArray.length; i++){
    myArray[i] = console.next().charAt(0);
    }

    converted = "";
    for (char temp : myArray)
    converted += (""+temp);
    }
    }[/HIGHLIGHT]
    Last edited by gszauer; 11-27-2007 at 04:04 PM.
    Quote Originally Posted by ~Aristotle
    It is the mark of an educated mind to entertain a tought without accepting it
    If my post was helpful, please help me build some rep

  5. #4
    lmc059 is offline Newbie
    Join Date
    Oct 2007
    Posts
    16
    Rep Power
    0
    thank you so much for that thats exactly what i was looking for im just getting assignments thrown at me its hard to keep up but again thank you

  6. #5
    gszauer's Avatar
    gszauer is offline Programmer
    Join Date
    Nov 2007
    Location
    Florida
    Posts
    113
    Rep Power
    16
    Youre welcome, if you need any more help, just post
    Quote Originally Posted by ~Aristotle
    It is the mark of an educated mind to entertain a tought without accepting it
    If my post was helpful, please help me build some rep

  7. #6
    lmc059 is offline Newbie
    Join Date
    Oct 2007
    Posts
    16
    Rep Power
    0
    i posted a new thread yesterday about double ended queues any help would be great

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Beginner Understanding instances
    By Tonchi in forum CSharp Tutorials
    Replies: 0
    Last Post: 05-18-2011, 09:56 AM
  2. Help understanding this
    By geno53 in forum General Programming
    Replies: 4
    Last Post: 01-15-2011, 08:19 PM
  3. understanding the code
    By prof.deedee in forum Java Help
    Replies: 3
    Last Post: 11-10-2009, 04:33 PM
  4. Java Understanding
    By DozyLa in forum Java Help
    Replies: 4
    Last Post: 05-01-2009, 12:23 AM
  5. plz help me in understanding this code
    By sweeeeeeety in forum Java Help
    Replies: 2
    Last Post: 04-28-2009, 07:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

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