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

Thread: Homework assistance

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Homework assistance

    I'm just starting out at Java programming so my problem is likely obvious. The program needs to prompt the user to enter an integer and checks whether the number is divisible by 4, 5 and 6, or some combination of them, or just one of them. It then needs to tell the user what the number is and isn't divisible by. I think my problem is with a boolean but right now my program only tells the user if the number is divisible, not if it isn't.

    import java.util.Scanner;
     
    public class Unit3PartOne {
     
    public static void main(String[] args) {
     
     
    Scanner input = new Scanner(System.in);
    System.out.print("Enter an integer: ");
    int num1 = input.nextInt();
     
    if (num1 % 4 == 0 && num1 % 5 == 0 && num1 % 6 == 0)
    System.out.println("Your number is divisible by 4, 5, and 6");
     
     
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Homework assistance

    You need to make a list of all the tests to be done to solve the problem and then write the code for each one and test it.

    It looks like the code makes the same test two times????

    --- Update ---

    #pawan4angel Please don't do an OPs work for him. See: http://www.javaprogrammingforums.com...n-feeding.html
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Location
    Earth
    Posts
    21
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Homework assistance

    OK

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Homework assistance

    @pawan4angel If you have any ideas on how the OP should think through the problem and work towards a solution that would be good. Maybe a few short code samples to show some ideas with explanations of what they do and why they work. Like a mini-tutorial
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Homework assistance

    Managed to solve my problem

Similar Threads

  1. [SOLVED] for loop assistance
    By Kseidel in forum Loops & Control Statements
    Replies: 3
    Last Post: September 17th, 2012, 08:10 PM
  2. Need some assistance please
    By JavaPhish in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2012, 10:00 AM
  3. New to the complmunity, need some assistance please.
    By nakedtriple in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 7th, 2011, 06:14 AM
  4. AI Search Simulator Assistance
    By GeekWarth in forum What's Wrong With My Code?
    Replies: 12
    Last Post: September 17th, 2011, 03:40 PM
  5. FileReader need assistance
    By tazjaime in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 8th, 2009, 01:12 AM