+ 1

Why this program is not running with Scanner correct instead of when i using main method the following program get run correct?

https://code.sololearn.com/chVteNcD7Ce8/?ref=app So can u tell me its happen why?? BTW i m using Scanner first time so see dat am i forgotten some method or something else?? [A^dr3w] Dan Walker ‎ ‏‏‎Sreejith 

11th Oct 2018, 3:31 AM
Harsh Agrawal
Harsh Agrawal - avatar
7 Respuestas
+ 1
Replace sc.next() with sc.nextLine()
11th Oct 2018, 4:51 AM
Anna
Anna - avatar
+ 2
Remove the semicolon after if() in line 19. It's not easy to understand what your code does without any comments and "reasonable" variable names. What is cn? What is p? It's also quite difficult to read because of its lack of indentation. You don't have to use indentation in languages like Java, but it's easier to read like this: for () { if() { while() { /* do something */ } } } It's helpful if you try to debug your code too.
11th Oct 2018, 5:11 AM
Anna
Anna - avatar
+ 1
@thnxzz i dont know much about scanner so can u xplain how can we use scanner???
11th Oct 2018, 4:53 AM
Harsh Agrawal
Harsh Agrawal - avatar
+ 1
sc.next() will read one word, sc.nextLine() will read an entire line https://www.sololearn.com/learn/Java/2220/
11th Oct 2018, 4:54 AM
Anna
Anna - avatar
+ 1
Anna can u check my this code as in this code der is two palindrome nd out coming three??? why https://code.sololearn.com/cSm35IBgT6fW/?ref=app
11th Oct 2018, 5:01 AM
Harsh Agrawal
Harsh Agrawal - avatar
+ 1
https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html This may help too. Being able to read and understand documentation is really useful to a programmer Notice the 'delimiter' options - this will be useful for your first code as you can delimit by spaces (which is what your if statement is doing) so this will make your code neater because it's delegating the task to another class
11th Oct 2018, 6:26 AM
Dan Walker
Dan Walker - avatar
0
as Dan Walker said indent your programs properly so that it's easier for you as well as others to read and understand.
12th Oct 2018, 4:22 PM
‎ ‏‏‎Anonymous Guy