Get the entire book!
Java for the Beginning Programmer

You must correct the following program. This program is attempting to add the numbers “2” and “3”, but it is currently displaying “23”. It should display “5”. Correct the program so that the numbers “2” and “3” are properly converted before they are added.

public class Assignment3
{
  public static void main(String args[])
  {
    String str1 = "1";
    String str2 = "2";

    System.out.println(“Result:” + (str1+str2) );
  }
}

Copyright 2005 - 2010 by Heaton Research, Inc.. Heaton Research™ and Encog™ are trademarks of Heaton Research. Click here for copyright and trademark information.