JAVA Programming for School

JAVA Programming for School

Share

If you have any problems in java programs, just post your question and mention your standard. We wil This page is exclusively made to clear all doubts.

Photos 01/12/2014

A smith number is a composite number, the sum of whose digits is the sum of
the digits of its prime factors obtained as a result of prime factorization
(excluding 1). The first few such numbers are 4, 22, 27, 58, 85, 94, 121 …

Example :

666
Prime factors are 2, 3, 3 and 37
Sum of the digits are (6+6+6) = 18
Sum of the digits of the factors (2+3+3+(3+7) = 18
_______________________________________________

import java.util.*;
public class SmithNo
{
boolean PriFac(int x,int y)//to check for the prime factors
{
int ctr=0;
for(int i=1; i0; x/=10)
sum+=(x%10);
return sum;
}

void main()
{
System.out.print("Enter the Number: ");
int n=new Scanner(System.in).nextInt();
int temp=n; //backup of n
int s=Sum(n); //finding the sum
int k=0; //counter to compute the sum of prime factors
System.out.print("\nThe Prime Factors are: ");
for(int i=2; i9)
k+=Sum(i); // adding the sum of digits of multi-digit number
else
k+=i; //adding the factors
System.out.print(i+" ");
n=n/i; //updation, n has to be changed everytime
}
}
}
System.out.println();
System.out.print("\nThe Sum of "+temp+" is: "+s);
System.out.print("\nThe Sum of the Prime Factors of "+temp+" is: "+s);
System.out.println();
if(s==k)
System.out.println("\nSmith number!!");
else
System.out.println("\nNOT a Smith number!!");
}
}

Want your business to be the top-listed Computer & Electronics Service in KOLKATA?
Click here to claim your Sponsored Listing.

Website

Address


Kolkata