-8

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?

1 Answers1

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