Solved

String to int ?

Posted on 1998-02-16
1
561 Views
Last Modified: 2010-04-16
Hi, how can I convert a String to int ?. Example:

  String a = "2";
  String b = "3";
  int na = (value of String a to int);  //int na = 2;
  int nb = (value of String b to int);  //int nb = 3;
  System.out.println(" a + b = " + (na + nb));

Thanks.




 
 
0
Comment
Question by:Deladier
1 Comment
 
LVL 32

Accepted Solution

by:
jhance earned 10 total points
ID: 1233082
String a = "2";
String b = "3";

int sum;

try{
  Integer iA = Integer(a);
  Integer iB = Integer(b);
}
catch (NumberFormatException e){
  // Error...
}

sum = iA.intValue() + iB.intValue();
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now