Computer Science, asked by aditi16hinger, 1 year ago

Write a programm in java to check whether the given number is niven number or not

Answers

Answered by Abrar11
0

Program to check the number is even or not a even number:-





import java.util.Scanner;

class CheckEven

{

public static void main(String args[])

{

int num;

System.out.println("Enter an Integer number:");

//The input provided by user is stored in num

Scanner input = new Scanner(System.in);

num = input.nextInt();

/* If number is divisible by 2 then it's an even number

* else odd number*/

if ( num % 2 == 0 )

System.out.println("Entered number is even");

else

System.out.println("Entered number is not even");

}

}


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