Computer Science, asked by mraggressive2005, 10 months ago

write a program to check whether a number is niven or not in blue j

Answers

Answered by Paulian42
5

import java.io.*;

class Niven

{

   public static void main(String args[])throws IOException

   {

       InputStreamReader in = new InputStreamReader(System.in);

       BufferedReader br = new BufferedReader(in);

       System.out.print("Enter the number: ");

       int n = Integer.parseInt(br.readLine());

       int sum = 0;

       for(int i = n; i != 0; i /= 10)

           sum += i % 10;

       if(n % sum == 0)

           System.out.println(n + " is Niven.");

       else

           System.out.println(n + " is not Niven.");

   }

}

Mark The brainliest

Answered by Anonymous
12

Answer:

import java.util.*;

class HarshadNumber

{

public void Display()

{

Scanner sc=new Scanner(System.in);

System.out.println ("Enter a number");

int num=sc.nextInt();

int c=num, d, sum=0;

while(c>0)

{

d=c%10

sum=sum+d;

c=c/10;

}

if (n%sum==0)

System.out.println(n+"is a Niven Number");

else

System.out.println(n+"is not a Niven Number");

}

}

Similar questions