+ 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 Réponses
+ 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
Solo Wanderer 4315
Solo Wanderer 4315 - 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