To check whether a number is a smith number or not

Page 1 of 1

3 Replies - 41576 Views - Last Post: 01 February 2009 - 01:38 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=83936&amp;s=b2dea128c3a2fc2863b90fd944158007&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 priya_lorha

Reputation: 6
• Posts: 82
• Joined: 02-August 08

To check whether a number is a smith number or not

Posted 01 February 2009 - 01:09 AM

```// to chk whether a nos is a smith nos or not

class smith
{
public static void main (int n)
{
int p=0,r,rem,qu,sum=0,q,s=0,fact,i,j,counter=0,ts=0;
//to find the sum of the digits
while(n>=1)
{
r=n%10;

s+=r;//sum of the digits

n=n/10;
}

// to check for factorials
for(i=1;i<n;i++)
{
if(n%i==0)
{// stores the factorials
fact=i;
//check for prime nos

for(j=2;j<fact;j++){

if(fact%n==0)

{counter++;}

if(counter<=2)
{
p=n;

//find the sum of the digits

while(p>=0){

rem=p%10;

p=p/10;

sum+=rem;

}//check for smith
}

if(sum==s)
System.out.println("The nos is  a smith nos");
else

System.out.println("The nos is not a smith nos");
}}}

}}

```

Is This A Good Question/Topic? 1

Replies To: To check whether a number is a smith number or not

#2 TriggaMike

• Using up all your 1's and 0's

Reputation: 85
• Posts: 1,103
• Joined: 26-September 08

Re: To check whether a number is a smith number or not

Posted 01 February 2009 - 01:14 AM

Yeah, try keeping track of your braces better, you are missing a closing brace, probably why your program isn't running.

#3 priya_lorha

Reputation: 6
• Posts: 82
• Joined: 02-August 08

Re: To check whether a number is a smith number or not

Posted 01 February 2009 - 01:34 AM

TriggaMike, on 1 Feb, 2009 - 12:14 AM, said:

Yeah, try keeping track of your braces better, you are missing a closing brace, probably why your program isn't running.

Then who come the programme is getting compiled

#4 ayman_mastermind

• human.setType("geek");

Reputation: 127
• Posts: 1,860
• Joined: 12-December 08

Re: To check whether a number is a smith number or not

Posted 01 February 2009 - 01:38 AM

you need to add a valid main method for your program such as:
```public static void main(String[] args){
}

```

and the main method that you have change it to another one and the printing should be dont in the main() method(the new one), and it would be better if your add public when defining your class for instance:
```public class smith {

```

i hope this helps, good luck