why is it not running? import java.util.Scanner; public class Myclass{ public static void main(String [] args){ Scanner in = new Scanner(System.in); String a; int b; System.out.println("enter a word"); a = in.nextLine(); System.out.println("enter repetition") b = in.nextInt(); for ( int = 0; x < b; x = x++) System.out.println(a); } } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why is it not running? import java.util.Scanner; public class Myclass{ public static void main(String [] args){ Scanner in = new Scanner(System.in); String a; int b; System.out.println("enter a word"); a = in.nextLine(); System.out.println("enter repetition") b = in.nextInt(); for ( int = 0; x < b; x = x++) System.out.println(a); } }

15th Sep 2016, 6:50 AM
vincent panaligan
vincent panaligan - avatar
8 Answers
+ 3
instead of in try another name for scanner variable. because in is already a static member of System class. and where is variable in ur for loop have u forget to write int x=0;
15th Sep 2016, 7:03 AM
Teja Naraharisetti
Teja Naraharisetti - avatar
+ 3
The problem seems to be a logical error. I suppose it is with the for loop control variable.
15th Sep 2016, 8:54 AM
Ousmane Diaw
+ 1
you didn't declare x and instead gave a value to the data type int
18th Sep 2016, 10:56 AM
Vivek Anand
+ 1
Where on earth is "x"???
11th Oct 2016, 2:37 AM
Sai Kartik
Sai Kartik  - avatar
+ 1
you could have used: Scanner sc=new Scanner (System.in);
11th Oct 2016, 2:38 AM
Sai Kartik
Sai Kartik  - avatar
+ 1
You see, you can name your Scanner object anything you like
17th Nov 2016, 11:23 AM
Sai Kartik
Sai Kartik  - avatar
0
thanks, but what do you think suits the best instead of using "in"?
15th Sep 2016, 3:00 PM
vincent panaligan
vincent panaligan - avatar
0
n
17th Sep 2016, 4:49 PM
Badrish
Badrish - avatar