Write a Java program to accept an integer and check if it is divisible by its last digit.
Display a message accordingly. (i.e. print Divisible or Not Divisible)
E.g. 36 is divisible by 6.
Answers
Answered by
1
Answer:
import java.util.Scanner;
public class program
{
public static void main ()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter any number");
int num = input.nextInt();
int last = num%10;
if (last == 0)
{
System.out.println("Can't Divide, Last digit is zero"):
}
else if (num%last == 0)
{
System.out.println("Divisible");
}
else
{
System.out.println("Not Divisible");
}
}
}
Similar questions