To check whether a number is a smith number or not

http://en.wikipedia.org/wiki/Smith_number, the program is not running

Page 1 of 1

3 Replies - 14855 Views - Last Post: 01 February 2009 - 01:38 AM Rate Topic: -----

#1 priya_lorha  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 78
  • Joined: 02-August 08

To check whether a number is a smith number or not

Post icon  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  Icon User is offline

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

Reputation: 85
  • View blog
  • Posts: 1,101
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 priya_lorha  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 78
  • Joined: 02-August 08

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

Posted 01 February 2009 - 01:34 AM

View PostTriggaMike, 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
Was This Post Helpful? 0
  • +
  • -

#4 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • 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 ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1