WAP to print to input a number and check if it is divisible by 15 or not.
java
Share
WAP to print to input a number and check if it is divisible by 15 or not.
java
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
Answer:
import.java.util.Scanner ;
public class DivisiblityTest
{
public static void main(String args[] )
{
Scanner sc = new Scanner(System.in) ;
boolean divby15 = false ;
int number, lastDigit, last2Digits;
System.out.println("Enter an integer : ") ;
number = sc.nextInt( ) ;
lastDigit = number % 10 ;
last2Digits = number % 100 ;
if (lastDigit = = 0 || lastDigit = = 3 )
divby15 = true;
if ( divby15 = = true)
System.out.println( number + "is divisible by 15" ) ;
else
System.out.println( number + "is NOT divisible " ) ;
}
}
Note :
A number is divisible by 15 , if the number is ending in either 0 or 5.