i am doing the coding of my minor project and for that i need to convert an input text(String) to an int type as i am inputting the data through swing component, panel as text(string). But internally i need to process that as int. so please tell me how can i convert it. For example, if my input String is "786", i should get its int value as 786.
please provide some code if possible.
adil_bashir
-7
Junior Poster in Training
Recommended Answers
Jump to PostSomething like this...
String input = "123"; int parsedInput = 0; try { parsedInput = Integer.parseInt(input); } catch(NumberFormatException nfe) { // Handle incorrect input }
Jump to Postbut what if my input string will be itself a string like this:
String input = "adil";
and i want to convert it into int like its ASCII value.
well you'd first make an int[] thats equal to the size of the string ie string.length() then you'd have a for …
Jump to Postplease provide full code as i dont know much about such problem
the code is basically done?:
int[] values=new int[input.length()];
the other im sure you can figure out ;)
All 12 Replies
SasseMan
49
Junior Poster
stultuske
commented:
no idea why this should be negative, since it is an answer to what the OP originally asked
+14
adil_bashir
-7
Junior Poster in Training
DavidKroukamp
105
Master Poster
Team Colleague
Featured Poster
adil_bashir
-7
Junior Poster in Training
DavidKroukamp
105
Master Poster
Team Colleague
Featured Poster
adil_bashir
-7
Junior Poster in Training
DavidKroukamp
105
Master Poster
Team Colleague
Featured Poster
adil_bashir
-7
Junior Poster in Training
DavidKroukamp
105
Master Poster
Team Colleague
Featured Poster
adil_bashir
-7
Junior Poster in Training
DavidKroukamp
105
Master Poster
Team Colleague
Featured Poster
adil_bashir
-7
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.