Tuesday, October 4, 2011

Finding the sum of a number and the number formed by reversing its digits (Java)

//This Java program accepts a number from the
//user and stores it. The program then finds
//the sum of the original number and the
//number formed by reversing its digits.
//For example if 521 is entered, the sum of 521
//and 125 is found out and printed.
import java.util.*;
class sumOfOriginalAndReverseNumber
public static void main()
    System.out.println("Enter a number");
    Scanner sc=new Scanner(System.in);
    int num_orig=sc.nextInt();
    int num_new=0,n=num_orig;
    System.out.println("The reversed number is "+num_new);
    int sum=num_orig+num_new;
    System.out.println("The sum of the original and reversed number is "+sum);
//Author : Mayank Rajoria

No comments:

Post a Comment