Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: code not returning sum

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default code not returning sum

    Hello. Writing Java is new to me, and I've been reviewing this code for awhile and I can't find what's different than my text book. Why won't it work? I want a sum to compute after the user types in two integers. I've even gone as far a counting the characters in each line--everything is the same. Thank you.

    <script type = "text/javascript">
    <!--
    var firstNumber; // first string entered by user
    var secondNumber; // second string entered by user
    var number1; //first number to add
    var number2; //second number to add
    var sum; //sum of number1 and number2

    // read in first number from user as a string
    firstNumber = window.prompt("Enter first integer" );

    // read in secondnumber from user as a string
    secondNumber = window.prompt("Enter second integer" );

    //convert numbers from strings to integers
    number1 = parseInt( firstNumber );
    number2 = parseInt( secondNumber );

    sum = number1 + number2; // add the numbers

    //display the results
    document.writeIn( "<h1>The sum is " + sum + "</h1>");
    // -->
    </script>


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: code not returning sum

    try asking your question on a javascript forum.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: code not returning sum

    Thank you! Apparently I am newer at this than I thought I was. Thank you!

  4. #4
    Junior Member Aju_21's Avatar
    Join Date
    Mar 2012
    Location
    Mumbai
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: code not returning sum

    error in this line
    document.writeIn( "<h1>The sum is " + sum + "</h1>");

    it is writeln i.e "L" and not "I"
    writeln means "write line"

    make the change,and it will work perfectly.

Similar Threads

  1. actionPerformed not returning a value.
    By gher in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 22nd, 2011, 10:15 AM
  2. Having trouble returning the right out put.
    By byako in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 26th, 2011, 11:49 PM
  3. Method returning 0 for everything
    By JJTierney in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 4th, 2010, 08:51 PM
  4. If statement not returning anything
    By Jonathan_C in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 15th, 2010, 03:38 PM
  5. returning a 2D array
    By straw in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2010, 04:30 AM