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: Begginer ~ why is my divider not working?

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    8
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Begginer ~ why is my divider not working?

    Hi

    I was hoping someone could help with my code. For some reasons, there is no divider in the operation. Iadded a print i to confirm the loop works. I tried with and without the brackets

    Can you use the i in the operations of the loop? I figured I could since printing it out give me a list of numbers

    Thanks


    public class harmonique {
     
        public static void afficherHarmonique( int wholeNumber ) {
            int harmonique = 1;
     
            for( int i = 2; i <= wholeNumber + 1; i = i + 1 ) {
                System.out.println ("i =" + i);
                harmonique = harmonique + (1/i);
                System.out.println ("harmonique =" + harmonique);
     
            }
        }
    }
    Last edited by Christian_Doucet; April 14th, 2014 at 06:45 PM.


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Begginer ~ why is my divider not working?

    Actually its working, it just that you didn't noticed that it is working since you are using an int primitive type.
    1 divided by i (which is integer) will make result equal to zero (without decimal places) if I am not wrong. you better use double or float primitive type if your are expecting decimal places.

  3. The Following User Says Thank You to dicdic For This Useful Post:

    Christian_Doucet (April 14th, 2014)

Similar Threads

  1. HW BEGGINER HELP !
    By begginerJava in forum Object Oriented Programming
    Replies: 5
    Last Post: April 14th, 2014, 11:54 AM
  2. Java help with Methods (Begginer)
    By maddiexc in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 15th, 2013, 10:53 PM
  3. Java Help for a begginer
    By miller4103 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 15th, 2013, 09:00 PM
  4. help im a begginer
    By ivankov2 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 24th, 2011, 07:33 AM
  5. Any ideas for begginer?
    By SwEeTAcTioN in forum Java Theory & Questions
    Replies: 11
    Last Post: October 27th, 2009, 03:28 AM