WAP in Java to find whether the number is NIVEN or not . (NIVEN number is a which is divisible by the sum of it's digit)
Answers
Explanation:
hope this answer will be helpful...
Program of Niven or not
Output:
Enter the number:
450
number is niven
Explanation:
import java.util.*; // Import Package
public class Main // main class
{
public static void main(String[] args) // main method
{
int sum =0; // variable declaration
Scanner sc2 = new Scanner(System.in); // creating the object of scanner
System.out.println(" Enter the number:");
int n= sc2.nextInt(); // taking input
int n1=n; // assigning this to another number
while(n1>0) // iterating the loop
{
int rem=n1%10; // calculating reminder
sum=sum+rem; // finding the sum of digit
n1=n1/10; // obtain quotient
}
if(n%sum==0) // checking the condition
System.out.println("number is niven");
else
System.out.println(" number is not niven");
}
}
Following are the description of program
- Creating the instance of scanner class sc2 for taking the user input in the variable "n" .
- The nextInt() method is used for taking input in the integer type .
- After that iterating the while loop to calculating the sum of digit of number of variable "n".
- The "sum" variable is used for finding the sum of digit .
- Finally the if condition is used for check number is niven or not.
Learn More
https://brainly.in/question/1353601