The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 3 of 3

Thread: JAVA need HELP!

  1. #1

    JAVA need HELP!

    My assignment is input 5 integer (have to show in xhtml) and deter main largest and smallest Integer. I am including the script:

    <?xml version ="1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <!-- Fig. 7.6: welcome5.html-->
    <!--- Using Promt Boxes -->


    <html xmlns ="http://www.w3.org/1999/xhtml">

    <head>

    <title> Using Promt and Alart Boxes</title>

    <script type="text/javascript">

    <!--

    var x,y,z,o,p, result;
    var xVal, yVal, zVal, oVal, pVal;

    // read the name from the prompt box as a string
    xVal = window.prompt("please enter your first integer", "0");
    yVal = window.prompt("please enter your second integer", "0");
    zVal = window.prompt("please enter your first integer", "0");
    oVal = window.prompt("please enter your first integer", "0");
    pVal = window.prompt("please enter your first integer", "0");

    x=parseInt (xVal);
    document.writeln("<br/>First number is: " +x);
    y=parseInt (yVal);
    document.writeln("<br/>Second number is: " +y);
    z=parseInt (zVal);
    document.writeln("<br/>Third number is: " +z);
    o=parseInt (oVal);
    document.writeln("<br/>Fourth number is: " +o);
    p=parseInt (pVal);
    document.writeln("<br/>Fifth number is: " +p);


    static int smallest(int x, int y, int z) {
    if (x <= y && x <= z) {
    return x;
    }
    else if (y <= x && y <= z) {
    return y;
    }
    else
    return z;
    }


    : I gave uppp


    //-->

    </script>

    </head>

    <body>
    <p> click Refresh to run this script again.</p>
    </body>

    </html>

  2. #2
    Hey man.
    1) This is JavaScript, not Java.
    2) I won't give you a solution. If I do, you won't learn how to code. muhwahwahwa. :insert evil laugh smiley here:
    3) Here's the pseudo code:

    Code:
    <script type="text/javascript">
    
    numArray = create a new array with size of 5;
    
    a for loop from i = 0 to i < 5, stepsize 1.
    {
    prompt user for a value, and insert it into i-th index of the numArray.
    }
    
    //find min
    minNum is 0-th element of numArray.
    a for loop from i = 1 to i < 5, stepsize 1.
    {
    if the i-th element is less than minNum, replace minNum with this i-th element.
    }
    
    //please do max on your own. (left to reader as an exercise. haha)
    </script>
    Do the parseInt stuff also, I left that out... (like type-checking stuff).

    And man, don't give up too soon. It's way too soon to give up! You gotta try harder man...

  3. #3

    i got it another way

    10 points for MOHAMMAD REZZA && PASS THE TEST55+10=65
    <?xml version ="1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <!-- Fig. 7.6: welcome5.html-->
    <!--- Using Promt Boxes -->


    <html xmlns ="http://www.w3.org/1999/xhtml">

    <head>

    <title> 10 points for MOHAMMAD REZZA && PASS THE TEST55+10=65</title>

    <script type="text/javascript">

    <!--

    var x,y,z,o,p,maxValue,minValue;
    var xVal, yVal, zVal, oVal, pVal;

    // read the name from the prompt box as a string
    xVal = window.prompt("please enter your first integer", "0");
    yVal = window.prompt("please enter your second integer", "0");
    zVal = window.prompt("please enter your first integer", "0");
    oVal = window.prompt("please enter your first integer", "0");
    pVal = window.prompt("please enter your first integer", "0");

    x=parseInt (xVal);
    document.writeln("<br/>First number is: " +x);
    y=parseInt (yVal);
    document.writeln("<br/>Second number is: " +y);
    z=parseInt (zVal);
    document.writeln("<br/>Third number is: " +z);
    o=parseInt (oVal);
    document.writeln("<br/>Fourth number is: " +o);
    p=parseInt (pVal);
    document.writeln("<br/>Fifth number is: " +p);


    {
    var maxValue;
    if (x>y)
    {
    maxValue =x ;
    }
    else
    {
    maxValue = y;
    }
    if (y>z)
    {
    maxValue =y ;
    }
    else
    {
    maxValue = z;
    }
    if (z>o)
    {
    maxvalue =z;
    }
    else
    {
    maxValue = o;
    }
    if (o>p)
    {
    maxvalue =o;
    }
    else
    {
    maxValue = p;
    }

    {
    document.writeln("<br/>The MAXIMUM number is: " +maxValue);
    }



    }


    {
    var minValue;
    if (x<y)
    {
    minValue =x ;
    }
    else
    {
    minValue = y;
    }
    if (y<z)
    {
    minValue =y ;
    }
    else
    {
    minValue = z;
    }
    if (z<o)
    {
    minValue =z;
    }
    else
    {
    minValue = o;
    }
    if (o<p)
    {
    minValue =o;
    }
    else
    {
    minValue = p;
    }

    {
    document.writeln("<br/>The MInImum number is: " +minValue);
    }



    }









    //-->

    </script>

    </head>

    <body>
    <p> click Refresh to run this script again.</p>
    </body>

    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012