/* * Lab 2, Practice writing Methods * * name: CS 112 Course Staff */ public class Methods { /* * print3Times - takes a string s and prints it 3 times */ public static void print3Times(String s) { for (int i = 0; i < 3; i++) { System.out.println(s); } } /* * printNTimes - takes a takes an integer n and a string s, * and prints the string n times */ public static void printNTimes(int n, String s) { for (int i = 0; i < n; i++) { System.out.println(s); } } public static void main(String [] args) { // Note: In order to print a double-quote character, // we need to precede it with a backslash! System.out.println("Testing print3Times(\"hello\")..."); print3Times("hello"); System.out.println("\nTesting printNTimes(5, \"hello\")..."); printNTimes(5, "hello"); System.out.println("\nTesting printNTimes(2, \"hello\")..."); printNTimes(2, "hello"); } }