Results 1 to 7 of 7
  1. #1
    MICHAELABICK is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default My program is not working

    i have built a program and it runs. The only problem is that i tell it to do an equation with a random number and it always gives me the number 0. Please help! Here is the program.







    import javax.swing.*;

    public class luck
    {
    private static int input;
    public static void main (String[] args)
    {
    int num1 = 4;
    int num2 = (int) (Math.round(Math.random()*25));
    int num3 = input;
    int answer;
    int Input;

    String input = JOptionPane.showInputDialog("Enter your happieness on a scale from 1-10");

    answer = num3*num1*num2;

    System.out.println("Answer: "+answer);

    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    what do you think the non-initialized variable "input" will equal? what will that make num3?

    Edit: On review of your posting history, I see that you never replied to answers to your previous question from November. I strongly advise you not to continue this behavior else no one will want to answer your questions. No one likes helping someone only to be ignored.

    Best of luck.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default The Basics..

    From the looks of your program, I strongly suggest reading the Java tutorials:
    The Java™ Tutorials
    ... and start to learn how to use the Java SE API:
    Java Platform SE 6

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    mohamed gaber is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Smile i solved your problem

    hi
    i modified your code and it is now working
    import javax.swing.*;

    public class arrays
    {

    public static void main (String[] args)
    {
    int num1 = 4;
    int num2 = (int) (Math.round(Math.random()*25));
    int num3 ;
    int answer;
    num3 = Integer.parseInt(JOptionPane.showInputDialog("Ente r your happieness on a scale from 1-10"));

    answer = num3*num1*num2;

    System.out.println("Answer: "+answer);

    }
    }

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default The forum is for learning...

    @Mohamed: I know you mean well, but giving complete code to the OP is not a good idea. You're actually not helping at all. The purpose of the forum is to help learn Java and giving complete solutions doesn't do that (too much tempation to "cut & paste & I'm done"). If you noticed, I didn't give the OP any code... I gave him links to study (due to the level of knowledge that is shown) and then if he had questions, the forum could help him further.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    mohamed gaber is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default replying on your objection

    Quote Originally Posted by CJSLMAN View Post
    @Mohamed: I know you mean well, but giving complete code to the OP is not a good idea. You're actually not helping at all. The purpose of the forum is to help learn Java and giving complete solutions doesn't do that (too much tempation to "cut & paste & I'm done"). If you noticed, I didn't give the OP any code... I gave him links to study (due to the level of knowledge that is shown) and then if he had questions, the forum could help him further.

    CJSL
    i know that the purpose is to make him learn but he made a code and he didnt know what is the mistake
    so i helped him to solve it
    i cut and paste the code because it is very important for the developer to read someones code and understand it
    so i give him this benefit
    i hope i replied u

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default uh... yeah

    The OP had so many errors in the code that it was obvious he/she didn't know what was going on. And, yes, you solved it for him/her (the OP didn't solve it).
    • Did you explain the errors to the OP? ...NO
    • If the OP couldn't understand the original code what makes you think that he/she will understand the code you provided?
    • Did the OP learn anything? ...NO

    I'm assuming that you don't have too much experience with developers forums. They all work the same way... they never give out complete code. They give hints, links, samples and examples so th OP can learn the language. Believe me (and I'm not trying to be mean) giving complete code does more damage, than not giving anything.
    Also, if you have noticed, the OP never comes back asking questions nor thanks anybody for the suggestions/posts.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. client not working
    By hit here in forum New To Java
    Replies: 2
    Last Post: 08-10-2008, 02:00 AM
  2. Replies: 8
    Last Post: 05-28-2008, 08:00 AM
  3. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  4. Replies: 0
    Last Post: 10-04-2007, 10:33 PM
  5. Working With ANT
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 09:16 PM

Posting Permissions

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