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 6 of 6

Thread: Want to print RESULT word before output

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Want to print RESULT word before output

    HI,

    I am new to JAVA. I am trying to add numbers by using the below code. I want the result to be displayed as "Result = "<result>. The program below directly outputs the result from var x = +y + +z; and i want to add the word "RESULT = " before it. Kindly help!

    <html>
      <body>
        <p>Click the button to calculate x.</p>
        <button onclick="myFunction()">Try it</button>
        <br/>
        <br/>Enter first number:
        <input type="text" id="txt1" name="text1">Enter second number:
        <input type="text" id="txt2" name="text2">
        <p id="demo"></p>
        <script>
          function myFunction() {
            var y = document.getElementById("txt1").value;
            var z = document.getElementById("txt2").value;
            var x = +y + +z;
            document.getElementById("demo").innerHTML = x;
          }
        </script>
      </body>
    </html>


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

    Default Re: Want to print RESULT word before output

    Moved. Java != javascript
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Want to print RESULT word before output

    OMG! Wow Java Script looks so complicated! *runs*

    Hehe just kidding

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  4. #4
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Print the word RESULT= in my code

    HI,

    I am trying to add 2 numbers in JAVA and using the below code. I want to print the output of the file as RESULT = <result>. It now just shows the result without any wordings before it. Could you please let me know how to display the result as RESULT = <result>

    <html>
      <body>
        <p>Click the button to calculate x.</p>
        <button onclick="myFunction()">Try it</button>
        <br/>
        <br/>Enter first number:
        <input type="text" id="txt1" name="text1">Enter second number:
        <input type="text" id="txt2" name="text2">
        <p id="demo"></p>
        <script>
          function myFunction() {
            var y = document.getElementById("txt1").value;
            var z = document.getElementById("txt2").value;
            var x = +y + +z;
            document.getElementById("demo").innerHTML = x;
          }
        </script>
      </body>
    </html>

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Print the word RESULT= in my code

    Please don't post multiple threads on the same topic.

    Threads merged.

  6. #6
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Want to print RESULT word before output

    People would love to aid you here - but this is a Java forum.

    You might find better luck using a Java Script forum. Google it and I am sure you will find one.
    Like Norm said above, the two are totally difference languages, Java is a general multi-purpose
    object orientated language for web and desktop development. Java Script is a scripting language
    used to write, well scripts for the web and webpages. Both languages may have similar names,
    but are pretty much world's apart in syntax.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. Print a given sentence forwards, backwards and every other word.
    By newbiegirl in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 24th, 2013, 05:45 AM
  2. Replies: 7
    Last Post: March 29th, 2013, 07:38 AM
  3. How to print numbers using do while, for loop and if else statement?
    By techlover in forum Loops & Control Statements
    Replies: 1
    Last Post: October 30th, 2012, 02:13 PM
  4. The java-output doesn't give the right result?
    By pinotje in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 31st, 2011, 01:00 PM