Print string multiple times based on input

Report a typo

Write a program that reads an integer and a string from the input. If the integer is greater than 0, print the string that many times. If the integer is 0 or negative, print "Invalid input!" without throwing any exceptions.

Sample Input 1:

3
Hello

Sample Output 1:

Hello
Hello
Hello

Sample Input 2:

0
World

Sample Output 2:

Invalid input!
Write a program in Java 25
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

// Read an integer from the input
String integerStr = reader.readLine();
int integer = Integer.parseInt(integerStr);

// Read a string from the input
String string = reader.readLine();

// Check if the integer is greater than 0
// If so, print the string that many times
// Otherwise, print "Invalid input!"

}
}

Create a free account to access the full topic