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!!![]()
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();.
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.
If my post was helpful, please help me build some repOriginally Posted by ~Aristotle
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![]()
Youre welcome, if you need any more help, just post
If my post was helpful, please help me build some repOriginally Posted by ~Aristotle
i posted a new thread yesterday about double ended queues any help would be great
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks