Write a program in a class called Q1 in the text box below t
Write a program in a class called Q1 in the text box below 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 Troy. Here are the sample runs:
<Output>
Enter an integer: 6
Troy
<End Output>
<Output>
Enter an integer: 15
HiFive Troy
<End Output>
<Output>
Enter an integer: 25
HiFive
<End Output>
<Output>
Enter an integer: 1
<End Output>
Solution
Please find my code.
Please let me know in case of any issue.
import java.util.Scanner;
public class Q1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n; // variable to store user input
// taking user input
System.out.println(\"Enter an integer: \");
n = sc.nextInt();
// if n is multiple of 5 then
if(n%5 == 0)
System.out.println(\"HiFive\");
else if(n%2 ==0 || n%3 == 0)
System.out.println(\"Troy\");
}
}
/*
Sample run:
Enter an integer:
5
HiFive
Enter an integer:
34
Troy
Enter an integer:
25
HiFive
*/


