non repeated code

PHOTO EMBED

Tue Oct 18 2022 19:15:06 GMT+0000 (Coordinated Universal Time)

Saved by @DonYall #java

// Initialize a Scanner
static Scanner s = new Scanner(System.in);

public static void main(String[] args) {
  System.out.println("Enter a number");
  printForUser("foo");

  System.out.println("Enter another number");
  printForUser("foo2");
  
  System.out.println("Enter yet another number");
  printForUser("foo3");
}
public static void printForUser(String printedText) {
  // Store a number from user input
  int n = s.nextInt();
  
  // Print the text for the amount stored
  for (int i = 0; i < n; i++) {
    System.out.println(printedText);
  }
}
content_copyCOPY