Computer Science, asked by bhairav22, 1 year ago

write a program using Java to check the number is Niven or not up to range 1 to 1000

Answers

Answered by nitish8089
0

code......
public class Program
{
public static void range(int i){
int temp=i;
int sum=0;
do{
int x=temp%10;
sum+=x;
temp/=10;
}while(temp>0);
if(i%sum==0){
System.out.print(i+" ");
}
}
public static void main(String[] args) {
System.out.println("niven number from 1 to 100");
System.out.println("________________________________________");
for(int i=1;i<=1000;i++){
Program.range(i);
}
System.out.println("________________________________________");
}
}


see \: out \: screen \: shot \: also
Attachments:
Answered by Anonymous
0

class niven_number

{

   public static void main(String hi[])

   {

       int d=0;

       int s=0;

        for(int n= 1;n<=1000;n++)

       {

         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");

       }

      }

   }

}

Similar questions