Answer the question
In order to leave comments, you need to log in
How to display a number with the reverse order of digits?
Write a method that takes a positive integer as a parameter and returns a number with the opposite digit order. For example, for parameter 123 the method will return 321, for parameter 120 the method will return 21.
I wrote a code that displays the reciprocal of the number, but of course I can’t perform operations with it ... What needs to be corrected in the code in order to complete the task correctly? (Yes , I know that the method does not return anything, but only such an option comes to my mind)
import java.util.*;
class Practice2{
static Scanner eva = new Scanner(System.in);
public static void main(String[] args) {
int x,y;
x = eva.nextInt();
what(x);
}
static void what(int a) {
int b;
while(a>0) {
b = a%10;
a/=10;
System.out.print(b+"");
}
}
}
Answer the question
In order to leave comments, you need to log in
static int what(int a) {
int result = 0;
while (a > 0) {
result = result * 10 + a % 10;
a = a / 10;
}
return result;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question