In Java. what is method to get the value of a string variable.?
-
If i have a code string a="1"; a=a+1; output is a1. i want the output=2. so what is method to get the value of a string variable.
-
Answer:
string a="1"; int N=Integer.parseInt(a) +1; Now N value is 2.
Neha at Yahoo! Answers Visit the source
Other answers
If it's a properly formatted decimal integer, you can get it using the Integer.parseInt() method. For instance: int a=1; String s="1"; a+=Integer.parseInt(s); System.out.println(a); The above code would print the number 2 to the console. Note that if the string is NOT a properly formatted decimal integer, then parseInt() will throw an exception. Only use it when you know it will work, or when you are prepared to handle the exception.
green meklar
Related Q & A:
- How to get the column value when a row is selected in wpf listview?Best solution by Stack Overflow
- How to get the Value of a TextArea?Best solution by Stack Overflow
- How do I get a value from a JObject?Best solution by Stack Overflow
- What's the linear mass density of a string?Best solution by Answerbag.com
- How to insert a date variable in java?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.