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

Thread: Trouble calculating a product and allowing a user to specify a range

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trouble calculating a product and allowing a user to specify a range

    I'm in a beginning programming class and am having trouble with this question:
    Write an application that gives you the product of odd integers from 3 to 35. Now change your program to allow a user to specify a range to calculate.

    So far, I have-

    package HMWK; //


    import javax.swing.*;

    public class HMWK {

    public static void main( String args[] )
    {
    int product = 1;int num1; String input;

    input= JOptionPane.showInputDialog ("Enter your number");
    num1= Integer.parseInt(input);

    for ( int x = 0; x <= 15; x += 2 )
    product *= x;


    JOptionPane.showMessageDialog( null, "Your product is " + product,
    "Odd Product", JOptionPane.INFORMATION_MESSAGE );

    System.exit( 0 );
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Trouble calculating a product and allowing a user to specify a range

    What does your program do? Does it compile? Does it run? Does it give you any errors? Does it do what you expect? Where are you stuck?
    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!

Similar Threads

  1. TFTP Server not allowing data transfer
    By ZX81 in forum What's Wrong With My Code?
    Replies: 19
    Last Post: April 8th, 2012, 09:26 AM
  2. Dialog box not allowing user input?
    By michaelgilbert in forum AWT / Java Swing
    Replies: 13
    Last Post: November 1st, 2011, 05:22 PM
  3. Product of array values
    By tarkal in forum Collections and Generics
    Replies: 13
    Last Post: September 27th, 2011, 05:27 PM
  4. calculate sum and product
    By swampfox in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 27th, 2011, 03:55 PM
  5. Allowing user to input variable.
    By That1guy in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 15th, 2010, 11:30 PM