Write a program to input an integer and
- display the reverse
- display the sum of each digit
- should include logic that considers the input
number as any number of digits long

Answer Posted / yagnik

/*
* Copyright 2002 Sun Microsystems, Inc. All Rights
Reserved.
*
* Redistribution and use in source and binary forms, with
or
* without modification, are permitted provided that the
following
* conditions are met:
*
* -Redistributions of source code must retain the above
copyright
* notice, this list of conditions and the following
disclaimer.
*
* -Redistribution in binary form must reproduce the above
copyright
* notice, this list of conditions and the following
disclaimer in
* the documentation and/or other materials provided with
the
* distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names
of
* contributors may be used to endorse or promote products
derived
* from this software without specific prior written
permission.
*
* This software is provided "AS IS," without a warranty of
any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS
AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT,
ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR
ANY
* DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
OF OR
* RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE
SOFTWARE OR
* ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS
BE LIABLE
* FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
INDIRECT,
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
ARISING OUT OF
* THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS
BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that Software is not designed, licensed
or
* intended for use in the design, construction, operation
or
* maintenance of any nuclear facility.
*/

import java.io.*;
import java.net.*;
import java.util.*;

/**
* This example shows how to use sockets and serialization
to send
* objects that will be received
* (see class Server to see the receiving part)
*
* Compiled and Tested with JDK1.1 & JDK1.2
*/
public class Client {

public static int x=0,sum=0;
public static void main(String args[]) {

int number=3256;
reverse(number);

}

public static void reverse(int n){


while(n!=0){
x=n%10;
System.out.print(x);
sum=sum+x;
n=n/10;

}

System.out.println(" Sum of digit==="+sum);
}

Is This Answer Correct ?    23 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Using C# Write a program that performs the following. The user inputs a number and then enters a series of numbers from 1 to that number. Your program should determine which number (or numbers) is missing or duplicated in the series, if any. For example, if the user entered 5 as the initial number and then entered the following sequences, the results should be as shown. Input Sequence Output ---------------------- --------------- 1 2 3 4 5 Nothing bad However, if 7 were the high number, the user would see the results on the right for the following number entries: Input Sequence Output ---------------------- --------------- 1 3 2 4 5 Missing 6 Missing 7 And if 10 were the high number and the user entered the numbers shown on the left, note the list of missing and duplicate numbers: Input Sequence Output ---------------------- --------------- 1 2 4 7 4 4 5 10 8 2 6 Duplicate 2 ( 2 times) Missing 3 Duplicate 4 ( 3 times ) Missing 9 The program should check the high number that the user inputs to ensure that it does not exceed the size of any array you might be using for storage.

3707


c# code to Count number of 1's in a given range of integer (0 to n)

4303


Hello Sir, Thanks for the Solution but, can you pls. Explain the coding for the Static Function & static variable from the below coding....waiting for Ans. class fact { public static void Main() { fact f=new fact(); int x=1; //Declaration of x as 1 int k=Convert.ToInt32(Console.ReadLine()); for(int i=1;i<=k;i++) { x= x *i; } System.Console.WriteLine(x); } }

2033


How to add a value from textBox over an existing certain column in SQL Server

2258


Write a program to convert postfix expression to infix expression.

4114






Give the code for Handling Mouse Events?

1883


Hello I am hosting remoting within IIS. Everything works just fine as long as I allow anonymous access at the IIS level. When I allow only Windows Authenticated sessions, something very strange happens: If the client activates the remote object with IP address - works fine If the client activates it using a machine name - get http 401 exception is thrown. The exception is thrown when the client calls the remote method. I set the channel's useDefaultCredentials property to true. Any idea how to allow Windows Authentication? Here is the call stack: System.Net.WebException: The remote server returned an error: (401) Unauthorized .. ---> System.ComponentModel.Win32Exception: The target principal name is incorrect at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean handshakeComplete) at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob, Boolean handshakeComplete) at System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate) at System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate) at System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials) at System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials) at System.Net.AuthenticationState.AttemptAuthenticate (HttpWebRequest httpWebRequest, ICredentials authInfo) --- End of inner exception stack trace ---

4238


Write a function which accepts list of nouns as input parameter and return the same list in the plural form. Conditions: i) if last letter is r then append s ii) if word ends with y then replace it by ies iii) call this function in main() and produce the required output. for eg:- if chair is input it should give chairs as output.

3991


program for straight line(y=mx+c)

5557


How to export 2 datatables of a single dataset to 2 different worksheets of a single MSExcel file ?

1945


I have this code in leftmenu.ascx page..now on leftmenu.ascx.cs page i want to access id values. but i dont want to check manually like Accommodation,Arts etc.. In cs file my code is like string str[]; //this array contains some values say 10 strings for(i=0;i<100;i++) { if(str[i]==id id.visible=true } i.e.i want to travel for each element of str and each value of id.if they match then id.visible=true how to do?

3820


How to Link Different Data Sources Together?

1803


Code for Searching for Multiple Matches with the MatchCollection Class?

2981


How to find No of classes,Packages,No of Methods per Classes and Depth of Inheritance for selecting source code in windows form application using c# .net? (Source code is input Program. It may be Java or .net) Please help me..) Thanks..)

2229


Code for IP Address Comparison and Conversion in C#?

3994