A good way to solve a bigger problem: split it into small, well-named helper methods, then combine them. Each helper does one clear job; the main method (or another method) calls them in order. Passing one method's result straight into another is called composing them.
// line() prints "----", title() prints "MENU" line(); title(); line();
Three tiny helpers, called in order, build a framed heading: ----, MENU, ----.
----
MENU
▶ Try it: the helpers line() and title() are defined for you. Run this, then reorder the calls and re-run.
line()
title()
doubleIt(n) returns n * 2 and addOne(n) returns n + 1. What is addOne(doubleIt(5))?
doubleIt(n)
n * 2
addOne(n)
n + 1
addOne(doubleIt(5))
Type exactly what this program prints.
public class Main { static void line() { System.out.println("--"); } static void title() { System.out.println("HI"); } public static void main(String[] args) { line(); title(); line(); } }
Sort each practice as a good use of helper methods or not.
True or false?