How to Get Main output into Common() method in Java?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.