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); } }
3 Answers
+ 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();
+ 1
Change int to String.
Make the L Capital in nextLine()
đ
+ 1
Thank you guys so much đ it worked. Now I can work on my new code