// This code sets things up for a general java program with input import java.util.Scanner; public class Methods1 { // order of methods does not matter in java // methods must be public static to be called by main in java public static void square() { Scanner scan = new Scanner(System.in); int userNum = promptInt("your number?"); System.out.println("square is " + userNum * userNum); } public static void cube() { Scanner scan = new Scanner(System.in); int userNum = promptInt("your number?"); System.out.println("cube is " + userNum * userNum * userNum); } public static void main(String[] args) { Scanner scan = new Scanner(System.in); // done with setup, main code starts here square(); // calling method cube(); // main code ends (still need the below two lines!!) } /* Simple Utility methods that prompt the user and return input If you enter the wrong type of input, the program will end with an error! */ // utility for reading in integer input public static int promptInt(String promptText) { System.out.print(promptText + " "); Scanner scan = new Scanner(System.in); int response = scan.nextInt(); return response; } }