Solved

String to int ?

Posted on 1998-02-16
1
571 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

705 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