I have this question I'm trying to finish.
Write a method that receives a String and an integer and then prints the string to the console that many times on the same line, separated by a space, a dash, a star, a dash, and another space.
Sample call:
myMethod("Matthew", 3);
Sample output:
Matthew -*- Matthew -*- Matthew
However, the method I've written doesn't print this output out. I'm new to java. So, help is very much appreciated.
/**
*
*/
package myloops;
import java.util.*;
/**
* @author
*
*/
public class Quiz {
/**
*
* @param name
* @param num
*/
public static void myMethod(String name, int num) {
for (int loop = 1; loop <= num; loop++ ) {
if (num%2 != 0) {
System.out.print("-*-");
} System.out.print(name);
}
}//end of other method
/**
* @param args
*/
public static void main(String[] args) {
myMethod("Matthew", 3);
} // end of main method
} // end of parent class