0
find the error
import java.util.Scanner; public class Myclass { public static void main(String [] args) { Scanner sc = new Scanner(System.in); String a; int b; System.out.println("enter a word"); a = sc.nextLine(); System.out.println("enter repetition"); b = sc.nextInt(); for ( int x=0; x < b; x++) { System.out.println(a); } } }
3 Answers
+ 2
If you are trying sololearn compiler
enter the string then the repetition in a new line
insert your input like this:
a
4
+ 1
There is nothing 'wrong' with this code, I can run it and it will work fine. What isn't great is that there is not check to see if the second input is actually an integer at all
0
use the eclipse