Program to reverse the number & calculate the sum of its digit

Program:
import java.util.*;
class Reverse
{public static void main(String args[])
{
int n,sum=0,r,rev=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number : ");
n=sc.nextInt();
while(n!=0)
{
r=n%10;
sum=sum+r;
rev=rev*10+r;
n=n/10;
}
System.out.println("Reverse of the number is: "+rev);
System.out.println("Sum of the digits is : "+sum);
}
}
Output:



Comments

Popular posts from this blog

Sequential File Allocation

Indexed File Allocation method

Linked File Allocation