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: Java code help

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java code help

    I need to write a script that finds the smallest of several non-negative intergers while using a sentinel-controlled lopp (-1 to exit window prompt).

    I know something's clearly wrong since the window prompt never disappears. Been trying for hours and I really don't feel like starting over. Any advice or help would be amazing since this is due very soon.

    Thanks a lot

     
    <?xml version = "1.0" encoding = "utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title></title>
     
    <p>Keep entering postive integer numbers, I will find the smallest. When you are done enter -1 to quit.</p>
    <script type="text/javascript">
    <!--
     
    var itemcount;
    var i;
    var small=0;
    var cal;
    number = window.prompt("Enter a number:");
    var count = parseInt(number);
    var myarray = new Array(count);
     
    for(i=0;i<count;i++)
    {
    myarray[i]= window.prompt("Enter a number:");
    if (number == -1) break;
    }
    cal=myarray[0];
    for(i=0;i<count;i++)
    {
    if(parseInt(myarray[i])< cal)
    cal= myarray[i];
    }
     
    document.writeln("Smallest of all input numbers is: " + cal);
    document.writeln("<br/>")
    document.writeln("Click Refresh (or Reload) to run this script again.")
    // -->
    </script>
     
    </head>
    <body>
    </body>
    </html>


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Java code help

    Javascript != java, and these are java forums. I have moved your post to the other programming languages forum.

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,162
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: Java code help

    Java != Javascript. I'm going to move this to the "Other Programming Languages" board.

    Also, you might consider using a more informative title. "Java code help" doesn't really tell anybody what you need help with- so how will the people who might be able to help you know they might be able to help you?

    Edit- Bahaha, great minds think alike?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java code help

    Sorry, very new to Java and these forums as well. Pulling my hair out right now, no idea where I'm going wrong.

    Thanks.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Java code help

    What happens when you run the script? What part of it is not working?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java code help

    This code is actually prompting. Though some errors in it but it's prompting and also, how are you calling this in your web page source?

Similar Threads

  1. Java files compilation with java code
    By stallapp in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: July 14th, 2011, 08:12 AM
  2. Replies: 10
    Last Post: April 5th, 2011, 09:09 AM
  3. [SOLVED] Help with Java Code.
    By metalx66 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 16th, 2011, 05:57 AM
  4. Replies: 2
    Last Post: August 1st, 2010, 06:29 AM
  5. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 10:18 PM