Welcome! Log In Create A New Profile

Advanced

Help me with question on methods...

Posted by jaxon5 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Help me with question on methods...
September 02, 2006 05:25PM
Here it is:
Write a method that creates and initializes a 2-D array of double. The size of the array is determined by the arguments of the methods, & the initialization values are a range determined by beginning and ending values that are also arguments of the method. Create a second method that will print the array generated by the first method. In main() test the methods by creating and printing several different sizes of arrays.
My question: How do I create a method that belongs to no class inparticular, in Java? I must've skipped this part somewhere in Jia.
I've tried it like this:
public class classA {
public static void main(String[] args) {
void doSomething(Type argument) {
// compiler does not allow me to do this.

// ...
Plus I'm assuming that the method isn't supposed to belong to main(), since the question specifies that main() should test these methods. I also can't create global methods either, as the compiler complains there too. HELP!
Re: Help me with question on methods...
September 02, 2006 11:35PM
This should point you in the right direction:

class A
{
	protected final static String str = "Foo";

	public static void main(String[] args)
	{
		doSomething("Bar"winking smiley;
	}
	
	public static void doSomething(String argument)
	{
		System.out.println(str + " " + argument);
	}
}
Sorry, only registered users may post in this forum.

Click here to login