0

Why doesn't this work?

I wrote this and it says that it cannot find symbol but I can't find the problem. Can anyone help? import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner SC = new Scanner (System.in); int name = SC.nextline(); System.out.println(name); } }

25th May 2017, 4:47 AM
Joar
3 Respuestas
+ 3
nextLine returns a string, an int cannot be assigned to the value of a string. Either do one of the following (not sure what you want) : 1) Make name a String String name = ... 2) Cast the String to an int int name = Integer.parseInt(...); 3) use nextInt(); int name = SC.nextInt();
25th May 2017, 4:51 AM
Rrestoring faith
Rrestoring faith - avatar
+ 1
Change int to String. Make the L Capital in nextLine() 😀
25th May 2017, 4:52 AM
TakshakSH
TakshakSH - avatar
+ 1
Thank you guys so much 😄 it worked. Now I can work on my new code
25th May 2017, 4:54 AM
Joar