?
Solved

String to int ?

Posted on 1998-02-16
1
Medium Priority
?
572 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 40 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

Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

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 functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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