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.


Reference:
(1) Course Book (The Complete Reference Java j2se) ; Page 114
(2) http://c-programming-sourcecode.blogspot.com/2012/08/integer-number.html?updated-min=2012-01-01T00:00:00-08:00&updated-max=2013-01-01T00:00:00-08:00&max-results=14

Source Code:

package ReverseNumber;
import java.util.Scanner;

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

return reverse;
}
int getsum()
{
return sum;
}
}

public class ReverseNumber
{
public static void main(String args[]) {
Scanner input =new Scanner(System.in);
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());
}
}

11 comments:

  1. package reverse;
    import java.util.Scanner;
    class number
    {
    int sum=0;
    int getValue()
    {
    return sum;
    }
    }

    public class Reverse
    {
    public static void main(String[] args)
    {
    Scanner s=new Scanner(System.in);
    number n=new number();
    int a,rev=0,num,sum=0;
    System.out.print("Enter the integer number : ");
    a=s.nextInt();
    num=a;
    while( num!=0)
    {
    rev=rev*10;
    rev=rev+num%10;
    num=num/10;
    sum+=rev;
    }
    System.out.println("After reverse :" +rev);

    double result=n.getValue();
    System.out.println("The sum of reversed number is :" +sum);
    }

    }


    ReplyDelete
  2. ID-201421066
    Batch:46th

    package ex4;
    import java.util.Scanner;
    class reverse {
    int sum = 0;
    int getvalue()
    {
    return sum;
    }
    }
    public class Ex4 {
    public static void main(String[] args) {

    Scanner h = new Scanner(System.in);
    reverse nm = new reverse();
    int m,rv=0,nber,sum=0;
    System.out.println("Plz enter the int number");

    m = h.nextInt();
    nber = m;

    while (nber!=0) {
    rv = rv*10;
    rv = rv+nber%10;
    nber = nber/10;
    sum+=rv;
    }
    System.out.println("Reverses " +rv);
    double result = nm.getvalue();
    System.out.println("These Reversed number is " +sum);
    }
    }

    ReplyDelete
  3. package ReverseNumber;
    import java.util.Scanner;

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

    return reverse;
    }
    int getsum()
    {
    return sum;
    }
    }


    public class ReverseNumber {

    public static void main(String args[]) {
    Scanner input =new Scanner(System.in);
    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());

    }}

    ReplyDelete
  4. package Inverse;
    import java.util.Scanner;
    class number
    {
    int sum=0;
    int getValue()
    {
    return sum;
    }
    }

    public class Inverse
    {
    public static void main(String[] args)
    {
    Scanner s=new Scanner(System.in);
    number n=new number();
    int x,Inv=0,num,sum=0;
    System.out.print("Enter the integer number : ");
    x=s.nextInt();
    num=x;
    while( num!=0)
    {
    Inv=Inv*100;
    Inv=Inv+num%100;
    num=num/100;
    sum+=Inv;
    }
    System.out.println("After Inverse :" +Inv);

    double result=n.getValue();
    System.out.println("The sum of Inverse number is :" +sum);
    }

    }

    ReplyDelete
  5. package reverse;
    import java.util.Scanner;
    class number
    {
    int sum=0;
    int getValue()
    {
    return sum;
    }
    }

    public class Reverse
    {
    public static void main(String[] args)
    {
    Scanner s=new Scanner(System.in);
    number n=new number();
    int a,rev=0,num,sum=0;
    System.out.print("Enter the integer number : ");
    a=s.nextInt();
    num=a;
    while( num!=0)
    {
    rev=rev*10;
    rev=rev+num%10;
    num=num/10;
    sum+=rev;
    }
    System.out.println("After reverse :" +rev);

    double result=n.getValue();
    System.out.println("The sum of reversed number is :" +sum);
    }

    }

    ReplyDelete
  6. package Inverse;
    import java.util.Scanner;
    class number
    {
    int sum=0;
    int getValue()
    {
    return sum;
    }
    }

    public class Inverse
    {
    public static void main(String[] args)
    {
    Scanner s=new Scanner(System.in);
    number n=new number();
    int x,Inv=0,num,sum=0;
    System.out.print("Enter the integer number : ");
    x=s.nextInt();
    num=x;
    while( num!=0)
    {
    Inv=Inv*100;
    Inv=Inv+num%100;
    num=num/100;
    sum+=Inv;
    }
    System.out.println("After Inverse :" +Inv);

    double result=n.getValue();
    System.out.println("The sum of Inverse number is :" +sum);
    }

    }

    ReplyDelete
  7. Name-Main Uddin
    ID-201421090
    Batch-46

    package exercise.pkg03;
    import java.util.Scanner;
    class MainGTR
    {
    int num;
    int Summation=0;
    int AUBReverse(){
    int RNumber = 0;
    int Rem = 0;
    do{
    Rem = num%10;
    RNumber = RNumber*10 + Rem;
    num = num/10;
    Summation=Summation+RNumber;
    }while(num > 0);
    return RNumber;
    }
    int getSummationValue()
    {
    return Summation;
    }
    }

    public class Exercise03 {

    public static void main(String[] args) {
    Scanner input =new Scanner(System.in);
    MainGTR CSE =new MainGTR();
    System.out.println("Please enter number : ");
    CSE.num = input.nextInt();
    int DimValue = CSE.AUBReverse();
    System.out.println("After Reverse Value : "+DimValue);
    System.out.println("Sum of Value : "+CSE.getSummationValue());
    }

    }

    ReplyDelete
  8. Md : jalis mahmud
    ID : 201420762
    Batch : 46th


    package reverse;
    import java.util.Scanner;
    class number
    {
    int sum=0;
    int getValue()
    {
    return sum;
    }
    }

    public class Reverse
    {
    public static void main(String[] args)
    {
    Scanner s=new Scanner(System.in);
    number n=new number();
    int m,rev=0,num,sum=0;
    System.out.print("Enter the integer number : ");
    m=s.nextInt();
    num=m;
    while( num!=0)
    {
    rev=rev*50;
    rev=rev+num%50;
    num=num/50;
    sum+=rev;
    }
    System.out.println("After reverse :" +rev);

    double result=n.getValue();
    System.out.println("The sum of reversed number is :" +sum);
    }

    }

    ReplyDelete
  9. e : Habibur Rahaman
    ID-201421091
    Batch-46

    package exercise.pkg03;
    import java.util.Scanner;
    class sajibxm
    {
    int m;
    int n=0;
    int AUB(){
    int NUM = 0;
    int Rem = 0;
    do{
    Rem = m%10;
    NUM = NUM*10 + Rem;
    m = m/10;
    n=n+NUM;
    }while(m > 0);
    return NUM;
    }
    int getSummationValue()
    {
    return n;
    }
    }

    public class Exercise03 {

    public static void main(String[] args) {
    Scanner input =new Scanner(System.in);
    sajibxm CTG =new sajibxm();
    System.out.println("Please enter number : ");
    CTG.m = input.nextInt();
    int DimValue = CTG.AUB();
    System.out.println("After Reverse Value : "+DimValue);
    System.out.println("Sum of Value : "+CTG.getSummationValue());
    }

    }

    ReplyDelete
  10. ID-201421092
    Batch-46

    package exercise.pkg03;
    import java.util.Scanner;
    class P
    {
    int m;
    int n=0;
    int ABC(){
    int NUM = 0;
    int Rem = 0;
    do{
    Rem = m%10;
    NUM = NUM*10 + Rem;
    m = m/10;
    n=n+NUM;
    }while(m > 0);
    return NUM;
    }
    int getSummationValue()
    {
    return n;
    }
    }

    public class Exercise03 {

    public static void main(String[] args) {
    Scanner input =new Scanner(System.in);
    P CTG =new P();
    System.out.println("Please enter number : ");
    CTG.m = input.nextInt();
    int DimValue = CTG.ABC();
    System.out.println("After Reverse Value : "+DimValue);
    System.out.println("Sum of Value : "+CTG.getSummationValue());
    }

    }

    ReplyDelete