# trigor656

angel sanchez
trigor656
3 Answer(s)      6 years and 10 months ago
Posted in : Java Beginners

HI, my teacher has given me a project in JAVA and i don't know what the code was can you help me. HERE'S THE PROBLEM...

write a method that tales an integer value and returns the number with its digit reverse.For Example given the number 7631 the method should return 1367

January 19, 2011 at 4:55 PM

Hi,

Try this:

```import java.util.*;

public class ReverseNumber {
public static int reverse(int num){
int n = num;
int reversedNumber = 0;
for (int i = 0; i <= num; i++) {
int r = num % 10;
num = num / 10;
reversedNumber = reversedNumber * 10 + r;
i = 0;
}
return reversedNumber;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number: ");
int num = input.nextInt();
System.out.println("Reversed Number: "+reverse(num));
}
}
```

Thanks

January 19, 2011 at 5:21 PM

```import java.util.*;
public class ReverseNumber {
public static int reverse(int num){
int n = num;
int reversedNumber = 0;
while(n>9){
int r=n%10;
n=n/10;
num = num * 10 + r
}
return num;
}

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number: ");
int num = input.nextInt();
System.out.println("Reversed Number: "+reverse(num));

}
}
```

January 20, 2011 at 6:24 PM

hi, MR/MS. unknown THANK YOU FOR THE CODE IT HELP ME A LOT... TILL NEXT TIME.....:); WAVE....