+ 1
Why i am getting this error
What is missing?? package com.helloworld; import java.util.Scanner; public class main { public static void main(String[] args) { System.out.println("Please input the string:"); Scanner b = new Scanner(System.in); System.out.println("Please input the number of times to repeat the string"); Scanner a = new Scanner(System.in); for(int i=a; i>0; i--) { System.out.println(b.nextLine()); } } }
8 Respostas
+ 4
Got it!
package com.helloworld;
import java.lang.String;
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please input the string:");
String string = scanner.nextLine();
System.out.println("Please input the number of times to repeat the string");
int integer = scanner.nextInt();
for(int i=integer; i>0; i--)
{
System.out.println(string);
}
}
}
+ 2
you didnt take any strings from user,you just created the object of scanner.
take that and put in a string variable
then try your code
+ 2
Try to convert the variable a into an integer first before you use it in the loop.
+ 2
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner a =new Scanner(System.in) ;
System.out.println ("enter your string");
String s=a.next() ;
System.out.println("your string is: "+s);
System.out.println ("how many repeats you want?");
int b=a.nextInt();
System.out.println (b);
for(int i=0;i<b;i++){
System.out.println(s);
}
}
}
😑 I WAS WRITING THIS 😂😢
+ 1
a.nextInt() in for loop maybe?
+ 1
blazingmagpie
i think in that case,user has to enter the string for many timez
+ 1
did it work?
+ 1
It worked, i got the soln.