GeekInterview.com
Answered Questions

Write a program to read a four digit integer and print the sum of its digits.Write a program that reads a floating point number and then displays the right-most digit of the integral part of the number.

Asked By: rishi | Asked On: Oct 21st, 2007

Answered by: karuna gaur on: Apr 15th, 2013

456 sum is 15

Code
  1. int sumDigits(int n) {
  2. int sum = 0;
  3.  
  4. while( n > 0 ) {
  5. sum += (n % 10); // add last digit of n to sum
  6. n /= 10; // divide n by 10 to "chop off" the last digit
  7. }
  8.  
  9. return sum;
  10.  
  11. getch();
  12. }

Answered by: mahamad on: Apr 17th, 2012

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5.         float f;
  6.         int s,r,k=1;
  7.         printf("Enter the number:=>");
  8.         scanf("%f",&f);
  9.         s=f/1;
  10.         while(k==1)
  11.         {
  12.                 r=s%10;
  13.                 printf("%d
  14. ",r);
  15.                 k++;
  16.         }
  17.         return 0;
  18. }

What is the difference between doget methods,doget()and service() used in servlet?Can we use service() methods replace of doget() and dopost()?

Asked By: ajay | Asked On: Aug 22nd, 2007

Answered by: kishore on: May 9th, 2012

OK,but my question is... In HttpServlet class service method calls doGet() or doPost() method .Intead of overriding doGet() or doPost(),why should we not override service() method itself?????

Answered by: Delindia Fathima on: Dec 20th, 2011

Yes we can override the service method in our servlet class. If we override the service method then we lose the functionality provided by the httpServlet class and doXXX() methods will not be called ...

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: