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

• September 15th, 2012, 11:18 PM
Rstuart970
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) {

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.
• September 15th, 2012, 11:50 PM
loui345
Re: PLZ HELP! Somethng wrong with code, assignment due today! Print if multiple of...
Better use tags
• September 16th, 2012, 02:12 AM
Rstuart970
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.
• September 16th, 2012, 02:32 AM
C++kingKnowledge
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
• September 16th, 2012, 02:35 AM
C++kingKnowledge
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