How to convert a string to int in java which is red during scanner function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to convert a string to int in java which is red during scanner function

26th Jan 2018, 10:49 AM
Mallikarjun h t
Mallikarjun h t - avatar
3 Answers
+ 5
Integer.parseInt();
26th Jan 2018, 10:55 AM
Faisal Rahman
Faisal Rahman - avatar
+ 3
@Mallikarjun h t Why did you tag c++ here? Please remove.
26th Jan 2018, 11:28 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
you can also instead of reading text with scanner read the input as integer with scanner.nextInt() instead of scanner.nextLine(). @Faisals answer is the universal method to convert strings to integers
26th Jan 2018, 11:06 AM
Jeremy
Jeremy - avatar