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

Answers were Sorted based on User's Feedback



Write a program to input an integer and - display the reverse - display the sum of e..

Answer / 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

Write a program to input an integer and - display the reverse - display the sum of e..

Answer / jayakrishnan

var v1 =
input.ToString().ToCharArray().Reverse().Cast<string>().ToArray();
Console.WriteLine(string.Join(string.Empty, v1));
var v2 = v1.Sum(o => int.Parse(o.ToString()));
Console.WriteLine(v2);

Is This Answer Correct ?    4 Yes 4 No

Post New Answer

More C Sharp Code Interview Questions

write a Program to copy the string using switch case.

0 Answers   Mind Tree, Wipro,


how does the below eqation proceed to be solved: x*=y+z options: x=x*y+z or x=x*(y+z)

1 Answers  


Code for Reading and writing from a file in c#?

1 Answers  


Code for IP Address Comparison and Conversion in C#?

0 Answers  


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

0 Answers   Eastcom Systems,


Code for Working with Files under a Directory?

1 Answers  


Write a program to convert postfix expression to infix expression.

0 Answers   Mind Tree,


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.

0 Answers   Mind Tree,


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); } }

0 Answers  


Write a program which has a function and that function should take 2 or 3 or any number of strings and it should return the largest common prefix of all those strings. If there is no common prefix it should return an empty string. for eg:- INPUT OUTPUT glo {glory,glorious,glod} gl {glad,glow} {calendar,phone} empty string

2 Answers   Mind Tree,


How to Create a Treeview Menu in ASP.NET with C#?

1 Answers  


Write a function which accepts a sentence as input parameter.Each word in that sentence is to be reversed. Space should be there between each words.Return the sentence with reversed words to main function and produce the required output. for eg:- i/p: jack jill jung kill o/p: kcaj llij gnuj llik

1 Answers   Mind Tree,


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)