Add Two Numbers in Java

Advertisement

In this section, you will learn to work with command prompt arguments provided by the user. We will access these arguments and print the addition of those numbers. In this example, args is an array of String objects that takes values provided in command

Add Two Numbers in Java

In this section, you will learn to work with
command prompt arguments provided by the user. We will access these
arguments and print the addition of those numbers. In this example, args
is an array of String objects that takes values provided in command prompt.
These passed arguments are of String types so these can't be added
as numbers. So to add, you have to convert these Strings in numeric
type (int, in this example). Integer.parseInt helps you to
convert the String type value into integer type. Now you can add these
values into a sum variable and print it on the console by println()
function.

Carla
October 14, 2012
Add 2 Numbers in Java
Tried the above code but it keeps on giving the following error....Exception in thread "main" java.lang.arrayindexoutofboundsexception:0 (error is the line below system.out.println....
Does anyone know how to fix this...
Thanks.