gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Design a java program that will input a number and will print "Divisible". If the number…
- User
Design a java program that will input a number and will print "Divisible". If the number is divisible by 5, otherwise print "Not Divisible". Use if else if else statement and Switch statement.
- Assistant
Here is the Java program using if-else if-else statement:
import java.util.Scanner; public class DivisibilityChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); if (number % 5 == 0) { System.out.println("Divisible"); } else { System.out.println("Not Divisible"); } } }And here is the Java program using switch statement:
import java.util.Scanner; public class DivisibilityChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); switch (number % 5) { case 0: System.out.println("Divisible"); break; default: System.out.println("Not Divisible"); break; } } }Both programs prompt the user to enter a number, calculate the remainder when the number is divided by 5, and then use if-else if-else or switch statement to determine whether the number is divisible by 5 or not.