Results 1 to 5 of 5
  1. #1
    smurf67 is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Angry Need Help with Java Assignment

    Hello,
    I am hoping someone can show me how to do this:

    I'm stuck on this problem and can't get it to work :(

    (While loop with counter control repetition) - Starting from number 100 count down to 1, using a while loop and a decrement operator. As your program counts down, every time you find a number that is exactly divisible by 9 (no remainder), print a line containing the number and the result (quotient) of the division.

    ANY help is much appreciated.

  2. #2
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default

    Help with what? Right now it doesn't seem like you've done anything. Post your best effort and ask specific questions about it. Don't forget to wrap the code in PHP tags, like this:
    PHP Code:
    code goes here

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What have you tried? This is a simple question to give you an introduction to while loops and if clauses. Give it your best attempt and post the code using code tags. If this whole task seems like a lot to you start small and first make the program loop from 100 down to 1.

  4. #4
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    Do you understand how while loop work ?

    if you not this one will help you .. learn .. try .. and show us your work

    The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

  5. #5
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    this for-loop starts at 100 and decrements 'i' each run until i=1
    Java Code:
    // i-- means decrement i
    // usually we go upwards like this: for (int i=1; i<=100; i++)
    for (int i=100; i>=1; i--) {
        //code goes here
    }

    as for checking if a number is wholly divisible by another number, you can use the MOD operator (% sign). MOD gives you the remainder from integer division. in integer division, if you make a calculation like this:
    Java Code:
    int cake = 50;
    
    int thirdCake = cake/3;
    //because integers are whole numbers they cannot store anything past the decimal point,
    //therefore thirdCake = 50/3 = 16, leaving the remaining .667
    
    int remainderCake = cake%3
    // 50%3 = 2, which makes sense because 16*3 = 48 leaving a remainder of 2.

    Back to the point, checking if a number is divisible by 9 means that checking there is NO REMAINDER after you divide by 9, i.e.
    Java Code:
    if (number%9 == 0) {
       //number is divisible by 9
    } else {
       //there is a remainder
    }

    hope this helps..

Similar Threads

  1. Java assignment.
    By jmsjames in forum New To Java
    Replies: 14
    Last Post: 12-07-2010, 03:18 AM
  2. Help me please (Java assignment)
    By cris_carriaga in forum Java Applets
    Replies: 4
    Last Post: 10-06-2010, 04:11 PM
  3. My java assignment -- please help me !
    By java_beginner1 in forum New To Java
    Replies: 11
    Last Post: 05-20-2010, 04:00 PM
  4. java assignment, need help bad.
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 04:53 PM
  5. Help with my assignment java
    By toby in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:59 AM

Posting Permissions

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