Computer Science, asked by Agkc, 1 year ago

Programming in java to find the no. is niven or not.. by scanner..


siddhartharao77: Is it even?
Agkc: Its Niven no.

Answers

Answered by siddhartharao77
1
import java.util.*;
public class Niven

  public static void main(String args[]) 
   {       
 Scanner demo = new Scanner(System.in);     
  System.out.print("Enter some number ");

        int a = demo.nextInt();

        int b = a, d, e = 0;   
              while(b>0)     
  {     
    d = b%10;       
    e = e + d;   
   b = b/10;   
     }            
 if(a%e == 0)     
 System.out.println("It is Niven Number."); 
      else       
 System.out.println("Not Niven Number");    
         }
}


Hope this helps!
Answered by Anonymous
1

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