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: PLZ HELP! Somethng wrong with code, assignment due today! Print if multiple of...

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PLZ HELP! Somethng wrong with code, assignment due today! Print if multiple of...

    Ok, I have spent to long trying to figure out what is keeping my code from printing both HiFive and Georgia for the right integer put in. Here is my assignment as it was given to me:

    3. (10 pts) Write a program that prompts the user to enter an integer. If the number is a multiple of 5, print HiFive. If the number is divisible by 2 or 3, print Georgia. Here are the sample runs:
    <Output> Enter an integer: 6
    Georgia
    <End Output>
    <Output> Enter an integer: 15
    HiFive Georgia
    <End Output>
    <Output> Enter an integer: 25
    HiFive
    <End Output>

    Here is my code I have now, Everything is working fine other then when I try the integer 15 it fails to give me both HiFive and Georgia since they are both multiple of 5 and happen to be divisible by 3 as well. My code as follows:

    // Unit 1 Assignment - #3

    import java.util.Scanner;

    public class HiFiveInteger {

    public static void main(String[] args) {


    // Ask for an integer
    Scanner input = new Scanner(System.in);
    System.out.print("Enter an integer: ");
    int num1 = input.nextInt();

    // Check if multiple of 5
    if (num1 % 5 == 0)
    {
    System.out.println("HiFive");

    }
    // Check if integer is divisible by 2 or 3
    else if (num1 % 2 == 0
    || num1 % 3 == 0)
    {
    System.out.println("Georgia");

    }


    }

    }

    Thank you very much in advance this is my first Java class and I am really enjoying it so far, I am also really liking this forum, I stumbled across it tonight and will be reading it daily.


  2. #2
    Member
    Join Date
    Jun 2012
    Posts
    105
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: PLZ HELP! Somethng wrong with code, assignment due today! Print if multiple of...

    Better use tags

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLZ HELP! Somethng wrong with code, assignment due today! Print if multiple of...

    Yeah sorry, first time posting here. I actually got my problem worked out, assigned HiFive and Georgia to variables and then just used if statements like i did before. I am not sure how they handle topics that do not need attention anymore but if they go about closing them or whatever, I no longer need assistance. Thank you.

  4. #4
    Member
    Join Date
    Jul 2012
    Posts
    71
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: PLZ HELP! Somethng wrong with code, assignment due today! Print if multiple of...

    just add another if statement specifying what to print in the case that an integer is divisible by both 5 and 3 (no else statement will be needed).... either hifive or georgia your choice

  5. #5
    Member
    Join Date
    Jul 2012
    Posts
    71
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: PLZ HELP! Somethng wrong with code, assignment due today! Print if multiple of...

    i see u said u already solved ur problem so disregard my statement... there is an option at the top right of the page (i think it's under thread tools) under the thread title you post where u can mark them as solved

Similar Threads

  1. Multiple nullpointerexceptions in my code.
    By javastudnt in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 2nd, 2011, 11:30 PM
  2. letterGrade not print out on my code
    By troj4nk1ng in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 8th, 2011, 08:31 PM
  3. Problem with code for school assignment?
    By Mellisa315 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 16th, 2010, 09:36 PM
  4. print code to browser
    By bookface in forum Java Theory & Questions
    Replies: 4
    Last Post: April 21st, 2010, 01:09 AM
  5. Can someone please tell me why my code doesn't print out anything?
    By deeerek in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 6th, 2010, 08:35 AM