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
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 |
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 |
How to add a value from textBox over an existing certain column in SQL Server
program for string reverse(eg:- i am boy -> boy am i)
8 Answers Black Pepper, Infosys, Mind Tree,
Write a program to count the number of characters, number of words, number of line in file.
how to change password in .net with c # with ado.net and also SQL server 2008 change password
<ul> <li id="Accommodation" runat="server" visible="false"><a href="../Elements/frmSearchAccommodation.aspx?submenuheader=1">Accommodation</a></li> <li id="Arts" runat="server" visible="false"><a href="../Elements/frmSearchProp.aspx?submenuheader=1">Arts And Props</a></li> <li id="Costume" runat="server" visible="false"><a href="../Elements/frmSearchCostume.aspx?submenuheader=1">Costume</a></li> <li id="Crew" runat="server" visible="false"><a href="../Elements/frmSearchCrew.aspx?submenuheader=1">Crew</a></li> <li id="Catering" runat="server" visible="false"><a href="../Elements/frmSearchCatering.aspx?submenuheader=1">Catering</a></li> <li id="Equipment" runat="server" visible="false"><a href="../Elements/frmSearchEquipment.aspx?submenuheader=1">Equipment</a></li> <li id="Film" runat="server" visible="false"><a href="../Elements/frmSearchFilmTapeStock.aspx?submenuheader=1">Film And Tape Stocks</a></li> <li id="Location" runat="server" visible="false"><a href="../Elements/frmSearchLocation.aspx?submenuheader=1">Location</a></li> <li id="Picture" runat="server" visible="false"><a href="../Elements/frmSearchPictureVehicle.aspx?submenuheader=1">Picture Vehicles</a></li> <li id="Production" runat="server" visible="false"><a href="../Elements/frmSearchProductionSupplies.aspx?submenuheader=1">Production Supplies</a></li> <li id="Post" runat="server" visible="false"><a href="../Elements/frmSearchPostProductionHouse.aspx?submenuheader=1">Post Production Houses</a></li> <li id="Rigging" runat="server" visible="false"><a href="../Elements/frmSearchRigging.aspx?submenuheader=1">Rigging</a></li> <li id="Stunt" runat="server" visible="false"><a href="../Elements/frmSearchStunt.aspx?submenuheader=1">Stunt</a></li> <li id="Studio" runat="server" visible="false"><a href="../Elements/frmSearchStudio.aspx?submenuheader=1">Studio</a></li> <li id="SFX" runat="server" visible="false"><a href="../Elements/frmSearchSFX.aspx?submenuheader=1">SFX</a></li> <li id="Talents" runat="server" visible="false"><a href="../Elements/frmSearchTalent.aspx?submenuheader=1">Talents</a></li> <li id="Transport" runat="server" visible="false"><a href="../Elements/frmSearchTransport.aspx?submenuheader=1">Transport</a></li> <li id="Venue" runat="server" visible="false"><a href="../Elements/frmSearchVenue.aspx?submenuheader=1">Venue</a></li> <li id="Other" runat="server" visible="false"><a href="../PageUnderConstruction.aspx?submenuheader=1">Other</a></li> </ul> 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?
Code for Reading and writing from a file in c#?
program to reverse the order of digits in a given number of any length.
write a Program to copy the string using switch case.
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
I am developing a web application using google map api.I want to update the map inside the div control within update panel. I got other controls updated but map doesn't get updated.I do not not want to update map whenever unnecessary controls are fired at server side.How could it be achieved?
working with arrays
How to Create a Treeview Menu in ASP.NET with C#?