The below code accepts an integer and checks and prints if <5, or if divisible by 5, or if divisible by 3 or if divisible by both 3 and 5. but I want to put the code into infinite looping so that the console repeatedly asks me to enter an integer after printing the output. Here is my code so far:
import java.util.Scanner;
public class Q3c {
public static void main(String args[]) {
System.out.println("Enter an integer ");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
if ((n%5 == 0) && (n%3 == 0)) {
System.out.println("The number " + n + " is divisible by 3 and 5");
}
else {
if(n%5 == 0) {
System.out.println(n + " is divisble by 5");
}
if(n%3 == 0) {
System.out.println(n + " is divisble by 3");
}
}
if (n < 5) {
System.out.println(n + "is <5");
}
input.close();
}
}
demo output:
Enter an integer 5
5 is divisibe by 5
Enter an integer