NY Regents Exam   Teasers   IQ Tests   Chemistry   Biology   GK   C++   Recipes   Search <  a href="/cgi/members/home.cgi" class="toplink">Members   Sign off

## Discussion topic: Contributed Answer/Explanation to Q. 1

#### Viewing messages

 Page 1 of 1 From: asha_g_mca Reply 1 of 11 Reply View replies (1) Subject: Contributed Answer/Explanation to Q. 1 ``` JAVA class smith { void main(int  n) { int d,sumd=0,sump=0,a=n,m,c=0; //checking for Prime number for(int i=1;i<=n;i++)  if (n%i==0) c++; if (c>2) { //sum of digits   while(a!=0) {d=a%10; a=a/10; sumd+=d; }   //sum of prime factors for(int i=2;i<=n;i++) { if (n%i==0) m=i; //checking for prime factor  int f=0; for(int j=1;j<=m;j++)  if (m%j==0) f++; if (f==2) { if (m<10) sump+=m; else{       a=m;       while(a!=0)       {d=a%10; a=a/10; sump+=d; }    } }  } if (sump==sumd)   System.out.println(n+"is a Smith number"); else  System.out.println(n+"is a Smith number"); } else System.out.println("You have entered a prime number.Prime cannot be a smith number"); } }                       ```Posted at: Tue Sep 14 06:28:07 2010 (GMT) From: asha_g_mca Reply 2 of 11 Reply Subject: Re: Contributed Answer/Explanation to Q. 1 ` good`Posted at: Tue Sep 14 06:34:05 2010 (GMT) From: debrup93 Reply 3 of 11 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` it is simply coded and easy to comprehend import java.io.*;class Smith{public static void main(String args[]){BufferedReader in=new BufferedReader(new InputStreamReader(System.in));int n,m,i=0;System.out.println("Enter any number");n=Integer.parseInt(in.readLine());m=n;String s="";s=in.readLine();int a[]=new int[s.length()];int d;while(d>1 && d{if(m%d==0){int k=1,s=0;while(k{if(d%k==0){s=s+k;}k++;}if(d+1==s){a[i]=d;i++;}d++;}int sum1=0,p=0;while(m>0){p=m%10;sum1=sum1+p;p=p/10;}for(i=0;i{int h,sum2=0;if(a[i]>0){h=a[i]%10;sum2=sum2+h;a[i]=a[i]/10;}}if(sum1==sum2)Sy stem.out.println("SMITH number");elseSystem.out.println("NOT SMITH number");}}```Posted at: Sat Nov 13 17:54:47 2010 (GMT) From: prashiss Reply 4 of 11 Reply Subject: Contributed Answer/Explanation to Q. 3 ``` At first we find the highest and the second highest element in the matrix. After that we sort the mtrix and print it. import java.io.*; class matrix { public static void main()throws IOException { int m, n, max, max2, temp; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the dimentions of the array ----->"); m=Integer.parseInt(br.readLine()); n=Integer.parseInt(br.readLine()); int A[][] = new int[m][n]; System.out.println("Enter the elements of the array ----->"); for(int i=0; i"); for(int i=0; i " + max); System.out.println("The 2nd max element of the array is -----> " + max2); for(int k=0; kA[k][j]) { temp = A[0][i]; A[0][i] = A[0][j]; A[0][j] = temp; } } } } System.out.println("The sorted elements of the matrix are-----> "); for(int i=0; i1)         {             inner:for(int j=2;j0)         {             s+=a%10;             a/=10;         }         return s;     } }         ```Posted at: Fri Feb 8 16:46:12 2013 (GMT) From: arpit159 Reply 8 of 11 Reply View replies (1) Subject: Contributed Answer/Explanation to Q. 2 ``` class string operation { public static void main(String args[]) { String w=""; // null string System.out.println ("Enter a String"); String str=br.readLine (); //user input string. int l=str.length(); int wl=checkvowel=checkcharecter=0; // initial zero System.out.println("Sentence No. of Vowels No. of Words"); // output outline for(i=0;i=l;i++) { char z=str.charAt (i); w=w+z; //picking each latter (character) and adding it to form a word. if(z=='!'||z=='.'||z=='?') { wl=w.length(); /* length of the word, which is form by adding each character */ for(int j=0;j=(wl-1);j++) /* j=(wl-1), because last character of the word w will be a special character (i.e. '!' , '.', '?') which is not need to be counted */ { char x=w.chatAt (j); //extraction of character from word if(x=='A'||x=='a'||x=='E'||x=='e'||x=='I'||x==i||x=='O'||x=='o'||x=='u'||x== 'U') { //checking vowels. checkvowel++; //if vowel found in a word w, checkvowel value add up one. checkcharecter++; } checkcharecter++; //character present in the word is counted } //closing of word loop } //closing of finishing of word loop when encountered '!', '?', '.' System.out.println( checkvowel+" "+checkcharecter); w=""; //assigning null to word w, so it can form new word again } //closing of for loop } //closing of main }//closing of class ```Posted at: Fri Feb 8 20:44:47 2013 (GMT) From: arpit159 Reply 9 of 11 Reply Subject: Contributed Answer/Explanation to Q. 2 ``` class string operation { public static void main(String args[]) { String w=""; // null string System.out.println ("Enter a String"); String str=br.readLine (); //user input string. int l=str.length(); int wl=checkvowel=checkcharecter=0; // initial zero System.out.println("Sentence No. of Vowels No. of Words"); // output outline for(i=0;i=l;i++) { char z=str.charAt (i); w=w+z; //picking each latter (character) and adding it to form a word. if(z=='!'||z=='.'||z=='?') { wl=w.length(); /* length of the word, which is form by adding each character */ for(int j=0;j=(wl-1);j++) /* j=(wl-1), because last character of the word w will be a special character (i.e. '!' , '.', '?') which is not need to be counted */ { char x=w.chatAt (j); //extraction of character from word if(x=='A'||x=='a'||x=='E'||x=='e'||x=='I'||x==i||x=='O'||x=='o'||x=='u'||x== 'U') { //checking vowels. checkvowel++; //if vowel found in a word w, checkvowel value add up one. checkcharecter++; } checkcharecter++; //character present in the word is counted } //closing of word loop } //closing of finishing of word loop when encountered '!', '?', '.' System.out.println( checkvowel+" "+checkcharecter); w=""; //assigning null to word w, so it can form new word again } //closing of for loop } //closing of main }//closing of class ```Posted at: Fri Feb 8 20:46:55 2013 (GMT) From: mike_schofield Reply 10 of 11 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` Its an easy one:- import java.io.*; public class smith_no {  public static void main(String ar[])throws IOException  {      BufferedReader in=new BufferedReader(new InputStreamReader(System.in));      System.out.println("Enter your no.");      int n=Integer.parseInt(in.readLine());      int a,b,s1,c,d,e,s2;      s1=s2=0;      e=n;      for(a=2;a<=n;a++)      {          while((n%a)==0)          {              System.out.print(a+"..");              if(a<10)              s1=s1+a;                                else              {                  d=a;                  while(d!=0)                  {                      c=d%10;                      s1=s1+c;                      d=d/10;                  }              }              n=n/a;          }      }            while(e!=0)      {          c=e%10;          s2=s2+c;          e=e/10;      }          if(s1==s2)          System.out.println("SMITH NUMBER");                    else          System.out.println("NOT A SMITH NUMBER");        } } ```Posted at: Sun Feb 10 13:54:53 2013 (GMT) From: rishisuu Reply 11 of 11 Reply Subject: Contributed Answer/Explanation to Q. 1 ``` easy code   import java.io.*; public class Smith {public static void main(int a) { int s=0,sum=0,t=a;int k;int d=a; do{k=d%10; sum=sum+k; d=d/10;}while(d>0); int x=2; while (x<=t) { while (t%x==0) {int g=prime(x); if(g==1) {int pop=sumd(x); s=s+pop; t=t/x;} } x=x+1; } if(s==sum) System.out.println("Smith"); } public static int prime(int c) { int b=0; for(int i=1;i<=c;i++) {if(c%i==0) b++; } if(b==2) return 1; else  return 0; } public static int sumd(int pin) {int k,s=0; do{k=pin%10; s=s+k; pin=pin/10;}while(pin>0); return s; } } ```Posted at: Mon Jan 27 15:56:08 2014 (GMT) Page 1 of 1