Showing posts with label reverse. Show all posts
Showing posts with label reverse. Show all posts

Sunday, March 22, 2015

Reverse an Integer Number

Write a Java program to reverse an Integer number. After print the output, make the sum of all digits. Use Method. Do not use parameter. Return value from Method to the Main function.

(1) Course Book (The Complete Reference Java j2se) ; Page 114

Source Code:

package ReverseNumber;
import java.util.Scanner;

class Reversnum
int number;
int sum=0;
int reverse(){
int reverse = 0;
int remainder = 0;
remainder = number%10;
reverse = reverse*10 + remainder;
number = number/10;
}while(number > 0);

return reverse;
int getsum()
return sum;

public class ReverseNumber
public static void main(String args[]) {
Scanner input =new Scanner(;
Reversnum r =new Reversnum();
int number;
System.out.println("Please enter number to be reversed using Java program: ");
r.number = input.nextInt();
int a = r.reverse();
System.out.println("After Reverse : "+a);
System.out.println("Sum of : "+r.getsum());