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.