Assignment #3 | Heaton Research

Assignment #3

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-2008 by Heaton Research, Inc.