Computer Science, asked by vanshika1393, 1 year ago

write a program to input a number check in display whether it is a niven number or not

Answers

Answered by Toshiiii
4

import java.util.Scanner;

class OddOrEven

{

public static void main(String args[])

{

int x;

System.out.println("Enter an integer to check if it is odd or even");

Scanner in = new Scanner(System.in);

x = in.nextInt();

if (x % 2 == 0)

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

else

System.out.println("The number is odd.");

}

}

Answered by Anonymous
6

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