write a Java program to tell whether the number is Niven or not
Answers
Answered by
2
import java.util.*;
class EvenOrNot
{
public static void main(String args[])
{
int n;
Scanner y = new Scanner(System.in);
n=y.nextInt();
if(n%2==0) System.out.println(n+" is even");
else System.out.println(n+" is not even");
}
}
class EvenOrNot
{
public static void main(String args[])
{
int n;
Scanner y = new Scanner(System.in);
n=y.nextInt();
if(n%2==0) System.out.println(n+" is even");
else System.out.println(n+" is not even");
}
}
tanishagrahari2018:
no it is not an even or odd number program it is a Niven number program
Answered by
2
import java.util.*;
class niven_number
{
public void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number to check whether it is a niven number or not");
int n=sc.nextInt();
int d=0;
int s=0;
int cpy=n;
while(n>0)
{
d=n%10;
s=s+d;
n=n/10;
}
if(cpy%s==0)
{
System.out.println(cpy+" is a niven number");
}
else
{
System.out.println(cpy+" is not a niven number");
}
}
}
Similar questions
Hindi,
7 months ago
English,
7 months ago
Computer Science,
7 months ago
Math,
1 year ago
Chemistry,
1 year ago