Basically I've been set some work where I have to have 4 methods but I don't really understand how methods work. One of these methods basically has to print out two set statements that's it and I have no idea how to do it as most examples across the web deal with methods being used for maths and nothing as simple as printing out two lines for a title. Can anyone please help?
Asked
Active
Viewed 83 times
-8
-
1Please read a basic Java tutorial. – Sotirios Delimanolis Nov 25 '13 at 14:37
-
show a little work, code, effort. – jamesTheProgrammer Nov 25 '13 at 14:39
-
What exactly do you want your software to do? Show us output(s) and input(s), and a little code wouldn't hurt. – Elliott Frisch Nov 25 '13 at 14:40
-
I can't believe that "examples across the web" doesn't deal with printing !! – T-D Nov 25 '13 at 14:40
1 Answers
2
Method is just a way of extracting a piece of code and making it callable on demand. So if you print out two lines...
System.out.println("This is line 1");
System.out.println("This is line 2");
And you want to call it more than once, then you would extract it into a method.
private void myNewMethod()
{
System.out.println("This is line 1");
System.out.println("This is line 2");
}
Then call that method from anywhere in your program like so
myNewMethod();
These types of questions are off topic however as you need to demonstrate an understanding of your problem before we can help fix it.

Ross Drew
- 8,163
- 2
- 41
- 53