简体   繁体   English

Java 在不使用数组的情况下反转 int 值

[英]Java reverse an int value without using array

Can anyone explain to me how to reverse an integer without using array or String.谁能向我解释如何在不使用数组或字符串的情况下反转 integer。 I got this code from online, but not really understand why + input % 10 and divide again.我从网上得到这段代码,但不太明白为什么 + 输入 % 10 并再次除法。

while (input != 0) {
    reversedNum = reversedNum * 10 + input % 10;
    input = input / 10;   
}

And how to do use this sample code to reverse only odd number.以及如何使用此示例代码仅反转奇数。 Example I got this input 12345, then it will reverse the odd number to output 531.示例我得到这个输入 12345,然后它将奇数反转为 output 531。

Java reverse an int value - Principles Java反转int值-原理

  1. Modding (%) the input int by 10 will extract off the rightmost digit. 将输入int乘以(%)10将提取最右边的数字。 example: (1234 % 10) = 4 例如:(1234%10)= 4

  2. Multiplying an integer by 10 will "push it left" exposing a zero to the right of that number, example: (5 * 10) = 50 将整数乘以10将“向左推”,在该数字的右边显示零,例如:(5 * 10)= 50

  3. Dividing an integer by 10 will remove the rightmost digit. 将整数除以10将删除最右边的数字。 (75 / 10) = 7 (75/10)= 7

Java reverse an int value - Pseudocode: Java反转一个int值-伪代码:

a. 一种。 Extract off the rightmost digit of your input number. 提取输入数字的最右边的数字。 (1234 % 10) = 4 (1234%10)= 4

b. b。 Take that digit (4) and add it into a new reversedNum. 取数字(4)并将其添加到新的reverseNum中。

c. C。 Multiply reversedNum by 10 (4 * 10) = 40, this exposes a zero to the right of your (4). 将reversedNum乘以10(4 * 10)= 40,这将在您(4)的右边显示一个零。

d. d。 Divide the input by 10, (removing the rightmost digit). 输入除以10,(除去最右边的数字)。 (1234 / 10) = 123 (1234/10)= 123

e. e。 Repeat at step a with 123 在步骤a中重复123

Java reverse an int value - Working code Java反转一个int值-工作代码

public int reverseInt(int input) {
    long reversedNum = 0;
    long input_long = input;

    while (input_long != 0) {
        reversedNum = reversedNum * 10 + input_long % 10;
        input_long = input_long / 10;
    }

    if (reversedNum > Integer.MAX_VALUE || reversedNum < Integer.MIN_VALUE) {
        throw new IllegalArgumentException();
    }
    return (int) reversedNum;
}

You will never do anything like this in the real work-world. 在实际的工作环境中,您永远不会做这样的事情。 However, the process by which you use to solve it without help is what separates people who can solve problems from the ones who want to, but can't unless they are spoon fed by nice people on the blogoblags. 但是,在没有帮助的情况下用来解决问题的过程就是将能够解决问题的人与想要解决问题的人区分开来,但是除非他们被Blogoblags上的好心人喂饱,否则他们是无法做到的。

I am not clear about your Odd number. 我不清楚您的奇数。 The way this code works is (it is not a Java specific algorithm) Eg. 该代码的工作方式是(不是Java特定的算法)例如。 input =2345 first time in the while loop rev=5 input=234 second time rev=5*10+4=54 input=23 third time rev=54*10+3 input=2 fourth time rev=543*10+2 input=0 输入= 2345 while循环中的第一次rev = 5输入= 234第二时间rev = 5 * 10 + 4 = 54输入= 23第三时间rev = 54 * 10 + 3输入= 2第四时间rev = 543 * 10 + 2输入= 0

So the reversed number is 5432. If you just want only the odd numbers in the reversed number then. 因此,反转的数字是5432。如​​果您只想在反转的数字中使用奇数,那么。 The code is: 代码是:

while (input != 0) {    
    last_digit = input % 10;
    if (last_digit % 2 != 0) {     
        reversedNum = reversedNum * 10 + last_digit;

    }
    input = input / 10; 
}

Simply you can use this 只需使用即可

    public int getReverseInt(int value) {
        int resultNumber = 0;
        for (int i = value; i !=0; i /= 10) {
            resultNumber = resultNumber * 10 + i % 10;
        }
        return resultNumber;        
    }

You can use this method with the given value which you want revers. 您可以将此方法与要反转的给定值一起使用。

while (num != 0) {
    rev = rev * 10 + num % 10;
    num /= 10;
}

That is the solution I used for this problem, and it works fine. 那是我用于此问题的解决方案,并且工作正常。 More details: 更多细节:

num % 10

This statement will get you the last digit from the original number. 此语句将使您获得原始号码的最后一位数字。

num /= 10

This statement will eliminate the last digit from the original number, and hence we are sure that while loop will terminate. 该语句将消除原始数字中的最后一位,因此我们确定while循环将终止。

rev = rev * 10 + num % 10

Here rev*10 will shift the value by left and then add the last digit from the original. rev * 10会将值向左移动,然后加上原始数字的最后一位。
If the original number was 1258, and in the middle of the run time we have rev = 85, num = 12 so: 如果原始数字为1258,并且在运行时间的中间,我们的rev = 85,num = 12,则:
num%10 = 2 num%10 = 2
rev*10 = 850 转* 10 = 850
rev*10 + num%10 = 852 rev * 10 + num%10 = 852

import java.util.Scanner;

public class Reverse_order_integer {
    private static Scanner scan;

    public static void main(String[] args) {
        System.out.println("\t\t\tEnter Number which you want to reverse.\n");
        scan = new Scanner(System.in);
        int number = scan.nextInt();
        int rev_number = reverse(number);
        System.out.println("\t\t\tYour reverse Number is = \"" + rev_number
                           + "\".\n");
    }

    private static int reverse(int number) {
        int backup = number;
        int count = 0;
        while (number != 0) {
            number = number / 10;
            count++;
        }
        number = backup;
        int sum = 0;
        for (int i = count; i > 0; i--) {
            int sum10 = 1;
            int last = number % 10;
            for (int j = 1; j < i; j++) {
                sum10 = sum10 * 10;
            }
            sum = sum + (last * sum10);
            number = number / 10;
        }
        return sum;
    }
}
int aa=456;
int rev=Integer.parseInt(new StringBuilder(aa+"").reverse());

See to get the last digit of any number we divide it by 10 so we either achieve zero or a digit which is placed on last and when we do this continuously we get the whole number as an integer reversed. 请参阅获取任何数字的最后一位数字,然后将其除以10,以便获得零或最后一位数字,当我们连续执行此操作时,我们得到的整数为整数。

    int number=8989,last_num,sum=0;
    while(number>0){
    last_num=number%10; // this will give 8989%10=9
    number/=10;     // now we have 9 in last and now num/ by 10= 898
    sum=sum*10+last_number; //  sum=0*10+9=9;
    }
    // last_num=9.   number= 898. sum=9
    // last_num=8.   number =89.  sum=9*10+8= 98
   // last_num=9.   number=8.    sum=98*10+9=989
   // last_num=8.   number=0.    sum=989*10+8=9898
  // hence completed
   System.out.println("Reverse is"+sum);
public static void main(String args[]) {
    int n = 0, res = 0, n1 = 0, rev = 0;
    int sum = 0;
    Scanner scan = new Scanner(System.in);
    System.out.println("Please Enter No.: ");
    n1 = scan.nextInt(); // String s1=String.valueOf(n1);
    int len = (n1 == 0) ? 1 : (int) Math.log10(n1) + 1;
    while (n1 > 0) {
        rev = res * ((int) Math.pow(10, len));
        res = n1 % 10;
        n1 = n1 / 10;
        // sum+=res; //sum=sum+res;
        sum += rev;
        len--;
    }
    // System.out.println("sum No: " + sum);
    System.out.println("sum No: " + (sum + res));
}

This will return reverse of integer 这将返回整数的倒数

Just to add on, in the hope to make the solution more complete. 只是添加,希望使解决方案更加完整。

The logic by @sheki already gave the correct way of reversing an integer in Java. @sheki的逻辑已经给出了反转Java中整数的正确方法。 If you assume the input you use and the result you get always fall within the range [-2147483648, 2147483647] , you should be safe to use the codes by @sheki. 如果假设您使用的输入和得到的结果始终在[-2147483648, 2147483647]范围内,则可以安全使用@sheki的代码。 Otherwise, it'll be a good practice to catch the exception. 否则,捕获异常将是一个好习惯。

Java 8 introduced the methods addExact , subtractExact , multiplyExact and toIntExact . Java的8引入的方法addExactsubtractExactmultiplyExacttoIntExact These methods will throw ArithmeticException upon overflow. 这些方法将在溢出时抛出ArithmeticException Therefore, you can use the below implementation to implement a clean and a bit safer method to reverse an integer. 因此,您可以使用下面的实现来实现一种干净且更安全的方法来反转整数。 Generally we can use the mentioned methods to do mathematical calculation and explicitly handle overflow issue, which is always recommended if there's a possibility of overflow in the actual usage. 通常,我们可以使用上述方法进行数学计算并显式处理溢出问题,如果实际使用中可能出现溢出,则始终建议使用。

public int reverse(int x) {
    int result = 0;

    while (x != 0){
        try {
            result = Math.multiplyExact(result, 10);
            result = Math.addExact(result, x % 10);
            x /= 10;
        } catch (ArithmeticException e) {
            result = 0; // Exception handling
            break;
        }
    }

    return result;
}

Java solution without the loop. Java解决方案无循环。 Faster response. 反应更快。

int numberToReverse;//your number 
StringBuilder sb=new StringBuilder();
sb.append(numberToReverse);
sb=sb.reverse();
String intermediateString=sb.toString();
int reversedNumber=Integer.parseInt(intermediateString);
public static int reverse(int x) {
    boolean negetive = false;
    if (x < 0) {
        x = Math.abs(x);
        negative = true;
    }

    int y = 0, i = 0;
    while (x > 0) {
        if (i > 0) {
            y *= 10;
        }

        y += x % 10;
        x = x / 10;
        i++;
    }
    return negative ? -y : y;
}

Here is a complete solution(returns 0 if number is overflown): 这是一个完整的解决方案(如果数字溢出,则返回0):

public int reverse(int x) {
    boolean flag = false;

    // Helpful to check if int is within range of "int"
    long num = x;

    // if the number is negative then turn the flag on.
    if(x < 0) {
        flag = true;
        num = 0 - num;
    }

    // used for the result.
    long result = 0;

    // continue dividing till number is greater than 0
    while(num > 0) {
        result = result*10 + num%10;
        num= num/10;
    }

    if(flag) {
        result = 0 - result;
    }

    if(result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) {
        return 0;
    }
    return (int) result;
}
int convert (int n)
{
        long val = 0;

        if(n==0)
            return 0;

        for(int i = 1; n > exponent(10,  (i-1)); i++)
        {
            int mod = n%( (exponent(10, i))) ;
            int index = mod / (exponent(10, i-1));

            val *= 10;
            val += index;
        }

        if (val < Integer.MIN_VALUE || val > Integer.MAX_VALUE) 
        {
            throw new IllegalArgumentException
                (val + " cannot be cast to int without changing its value.");
        }
        return (int) val;

    }


static int exponent(int m, int n)
    {
        if(n < 0) 
            return 0;
        if(0 == n) 
            return 1;

        return (m * exponent(m, n-1));

    }

It's good that you wrote out your original code. 写下原始代码是一件好事。 I have another way to code this concept of reversing an integer. 我有另一种方式可以对这种反转整数的概念进行编码。 I'm only going to allow up to 10 digits. 我最多只允许输入10位数字。 However, I am going to make the assumption that the user will not enter a zero. 但是,我将假设用户不会输入零。

if((inputNum <= 999999999)&&(inputNum > 0 ))
{
   System.out.print("Your number reversed is: ");

   do
   {
      endInt = inputNum % 10; //to get the last digit of the number
      inputNum /= 10;
      system.out.print(endInt);
   }
   While(inputNum != 0);
 System.out.println("");

}
 else
   System.out.println("You used an incorrect number of integers.\n");

System.out.println("Program end");

A method to get the greatest power of ten smaller or equal to an integer: (in recursion) 一种获取小于或等于整数的十的最大幂的方法:(递归)

public static int powerOfTen(int n) {
    if ( n < 10)
        return 1;
    else
        return 10 * powerOfTen(n/10); 
}

The method to reverse the actual integer:(in recursion) 反转实际整数的方法:(递归)

public static int reverseInteger(int i) {
    if (i / 10 < 1)
        return i ;
    else
        return i%10*powerOfTen(i) + reverseInteger(i/10);
}

Even if negative integer is passed then it will give the negative integer Try This... 即使传递了负整数,也将给出负整数。

public int reverse(int result) {

    long newNum=0,old=result;
    result=(result>0) ? result:(0-result);

    while(result!=0){
        newNum*=10;
        newNum+=result%10;
        result/=10;
        if(newNum>Integer.MAX_VALUE||newNum<Integer.MIN_VALUE)
            return 0;
    }
    if(old > 0)
        return (int)newNum;
    else if(old < 0)
        return (int)(newNum*-1);
    else 
        return 0;
}

This is the shortest code to reverse an integer 这是反转integer的最短代码

int i=5263; 
System.out.println(Integer.parseInt(new StringBuffer(String.valueOf(i) ).reverse().toString()));

123 maps to 321, which can be calculated as 3*(10^2)+2*(10^1)+1 Two functions are used to calculate (10^N). 123映射到321,可以将其计算为3 *(10 ^ 2)+ 2 *(10 ^ 1)+1两个函数用于计算(10 ^ N)。 The first function calculates the value of N. The second function calculates the value for ten to power N. 第一个函数计算N的值。第二个函数计算10的值以乘N。

Function<Integer, Integer> powerN = x -> Double.valueOf(Math.log10(x)).intValue();
Function<Integer, Integer> ten2powerN = y -> Double.valueOf(Math.pow(10, y)).intValue();

// 123 => 321= 3*10^2 + 2*10 + 1
public int reverse(int number) {
    if (number < 10) {
        return number;
    } else {
        return (number % 10) * powerN.andThen(ten2powerN).apply(number) + reverse(number / 10);
    }
}

If the idea is not to use arrays or string, reversing an integer has to be done by reading the digits of a number from the end one at a time. 如果不打算使用数组或字符串,则必须通过一次从末尾读取一个数字来反转整数。 Below explanation is provided in detail to help the novice. 下面提供了详细的解释以帮助新手。

pseudocode : 伪代码:

  1. lets start with reversed_number = 0 and some value for original_number which needs to be reversed. 让我们以reversed_number = 0开头,并设置一些反转的original_number值。
  2. the_last_digit = original_number % 10 (ie, the reminder after dividing by 10) the_last_digit = original_number%10(即除以10后的提醒)
  3. original_number = original_number/10 (since we already have the last digit, remove the last digit from the original_number) original_number = original_number / 10(由于我们已经有最后一位数字,因此请从original_number中删除最后一位数字)
  4. reversed_number = reversed_number * 10 + last_digit (multiply the reversed_number with 10, so as to add the last_digit to it) reversed_number = reversed_number * 10 + last_digit(将reversed_number乘以10,以便将last_digit加到上面)
  5. repeat steps 2 to 4, till the original_number becomes 0. When original_number = 0, reversed_number would have the reverse of the original_number. 重复步骤2到4,直到original_number变为0。当original_number = 0时,reversed_number将具有与original_number相反的数字。

More info on step 4: If you are provided with a digit at a time, and asked to append it at the end of a number, how would you do it - by moving the original number one place to the left so as to accommodate the new digit. 有关第4步的详细信息:如果一次提供一个数字,并要求在数字的末尾附加数字,您将如何处理-通过将原始数字向左移动一位以适应新数字。 If number 23 has to become 234, you multiply 23 with 10 and then add 4. 如果数字23必须变为234,则将23乘以10,然后加4。

234 = 23x10 + 4; 234 = 23x10 + 4;

Code: 码:

public static int reverseInt(int original_number) {
        int reversed_number = 0;
        while (original_number > 0) {
            int last_digit = original_number % 10;
            original_number = original_number / 10;
            reversed_number = reversed_number * 10 + last_digit;    
        }
        return reversed_number;
    }
while (input != 0) {
  reversedNum = reversedNum * 10 + input % 10;
  input = input / 10;
}

let a number be 168, 设一个数字为168
+ input % 10 returns last digit as reminder ie 8 but next time it should return 6,hence number must be reduced to 16 from 168, as divide 168 by 10 that results to 16 instead of 16.8 as variable input is supposed to be integer type in the above program. +输入%10返回最后一位作为提醒,即8,但下一次应返回6,因此必须将数字从168减少到16,因为将168除以10得到的结果是16而不是16.8,因为变量输入应该是整数类型在上面的程序中。

It is an outdated question, but as a reference for others First of all reversedNum must be initialized to 0; 这是一个过时的问题,但作为其他参考。首先,reverseNum必须初始化为0;否则,必须为0。

input%10 is used to get the last digit from input input%10用于获取输入的最后一位数字

input/10 is used to get rid of the last digit from input, which you have added to the reversedNum input / 10用于删除输入中已添加到reversedNum的最后一位数字

Let's say input was 135 假设输入为135

135 % 10 is 5 Since reversed number was initialized to 0 now reversedNum will be 5 135%10是5由于反转的数字已初始化为0现在反转的数字将是5

Then we get rid of 5 by dividing 135 by 10 然后通过将135除以10来摆脱5

Now input will be just 13 现在输入将只有13

Your code loops through these steps until all digits are added to the reversed number or in other words untill input becomes 0. 您的代码将循环执行这些步骤,直到将所有数字都添加到反转的数字上,或者换句话说,直到输入变为0。

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class intreverse
{
public static void main(String...a)throws Exception
{
    int no;
    int rev = 0;
    System.out.println("Enter The no to be reversed");
    InputStreamReader str=new InputStreamReader(System.in);
    BufferedReader br =new BufferedReader(str);
    no=Integer.parseInt(br.readLine().toString());
    while(no!=0)
    {
        rev=rev*10+no%10;
        no=no/10;

    }
    System.out.println(rev);
}
}

If you wanna reverse any number like 1234 and you want to revers this number to let it looks like 4321. First of all, initialize 3 variables int org ; 如果您想反转任何数字,例如1234,并且想要反转该数字以使其看起来像4321,那么,首先初始化3个变量int org; int reverse = 0; int反向= 0; and int reminder ; 和int提醒; then put your logic like 然后把你的逻辑像

    Scanner input = new Scanner (System.in);
    System.out.println("Enter number to reverse ");
    int org = input.nextInt();
    int getReminder;
    int r = 0;
    int count = 0;

    while (org !=0){
        getReminder = org%10;
         r = 10 * r + getReminder;
         org = org/10;



    }
        System.out.println(r);

    }

You can use recursion to solve this. 您可以使用递归来解决此问题。

first get the length of an integer number by using following recursive function. 首先使用以下递归函数获取整数的长度。

int Length(int num,int count){
    if(num==0){
        return count;
    }
    else{
        count++;
        return Lenght(num/10,count);
    }
}

and then you can simply multiply remainder of a number by 10^(Length of integer - 1). 然后您可以简单地将数字的余数乘以10 ^(整数的长度-1)。

int ReturnReverse(int num,int Length,int reverse){
    if(Length!=0){
        reverse = reverse + ((num%10) * (int)(Math.pow(10,Length-1)));
        return ReturnReverse(num/10,Length-1,reverse);
    }
    return reverse;
}

The whole Source Code : 整个源代码:

import java.util.Scanner;

public class ReverseNumbers {

    int Length(int num, int count) {
        if (num == 0) {
            return count;
        } else {
            return Length(num / 10, count + 1);
        }
    }

    int ReturnReverse(int num, int Length, int reverse) {
        if (Length != 0) {
            reverse = reverse + ((num % 10) * (int) (Math.pow(10, Length - 1)));
            return ReturnReverse(num / 10, Length - 1, reverse);
        }
        return reverse;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        ReverseNumbers reverseNumbers = new ReverseNumbers();
        reverseNumbers.ReturnReverse(N, reverseNumbers.Length(N, 0), reverseNumbers.ReturnReverse(N, reverseNumbers.Length(N, 0), 0));

        scanner.close();
    }
}
public int getReverseNumber(int number)
{
    int reminder = 0, result = 0;
    while (number !=0)
    {
        if (number >= 10 || number <= -10)
        {
            reminder = number % 10;
            result = result + reminder;
            result = result * 10;
            number = number / 10;
        }
        else
        {
            result = result + number;
            number /= 10;
        }
    }
    return result;

}

// The above code will work for negative numbers also //上面的代码也适用于负数

Reversing integer 反转整数

  int n, reverse = 0;
  Scanner in = new Scanner(System.in);
  n = in.nextInt();

  while(n != 0)
  {
      reverse = reverse * 10;
      reverse = reverse + n%10;
      n = n/10;
  }

  System.out.println("Reverse of the number is " + reverse);
int n=78912;
while(n>0)
{
    System.out.print(n-10*(n/10));
    n=n/10;
}
 public static int reverseInt(int i) {
    int reservedInt = 0;

    try{
        String s = String.valueOf(i);
        String reversed = reverseWithStringBuilder(s);
        reservedInt = Integer.parseInt(reversed);

    }catch (NumberFormatException e){
        System.out.println("exception caught was " + e.getMessage());
    }
    return reservedInt;
}

public static String reverseWithStringBuilder(String str) {
    System.out.println(str);
    StringBuilder sb = new StringBuilder(str);
    StringBuilder reversed = sb.reverse();
    return reversed.toString();
}
public static int reverse(int x) {
    int tmp = x;
    int oct = 0;
    int res = 0;
    while (true) {
        oct = tmp % 10;
        tmp = tmp / 10;
        res = (res+oct)*10;
        if ((tmp/10) == 0) {
            res = res+tmp;
            return res;
        }
    }
}
    Scanner input = new Scanner(System.in);
        System.out.print("Enter number  :");
        int num = input.nextInt(); 
        System.out.print("Reverse number   :");
        int value;
        while( num > 0){
            value = num % 10;
            num  /=  10;
            System.out.print(value);  //value = Reverse
            
             }
// my answer was too late but still might be able to help someone in the future

// suppose that the number you want to reverse was type Integer
int originalNumber = 726372282;

// i will convert int to string using the toString() method of the Integer class
String numberToString = Integer.toString(originalNumber);

String reversedNumber = "";

// now, since that the number was already converted into a string
// we can use for loop to reverse the number
for (int index = numberToString.length() - 1; index >= 0; index--) {

    reversedNumber += numberToString.charAt(index); // keep adding numbers starting from last number of "numberToString"
}
// now, we will convert the "reversedNumber" into an Integer using its parseInt() method
int finalResults = Integer.parseInt(reversedNumber);

// finally, printing out the results
System.out.printf("Original: %d%nReversed: %d", originalNumber, finalResults);
}

} }

I used String and I converted initially the int to String .Then I used the reverse method. 我使用String ,最初将int转换为String然后使用反向方法。 I found the reverse of the number in String and then I converted the string back to int . 我在String找到了数字的String ,然后将字符串转换回int Here is the program. 这是程序。

import java.util.*;

public class Panathinaikos {
    public static void my_try()
    {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the number you want to be reversed");
        int number = input.nextInt();
        String sReverse = Integer.toString(number);
        String reverse = new StringBuffer(sReverse).reverse().toString();
        int Reversed = Integer.parseInt(reverse);
        System.out.print("The number " + number+ " reversed is " + Reversed);
    }
}
public static double reverse(int num)
{
    double num1 = num;
    double ret = 0;
    double counter = 0;

    while (num1 > 1)
    {   
        counter++;
        num1 = num1/10;
    }
    while(counter >= 0)
    {
        int lastdigit = num%10;
        ret += Math.pow(10, counter-1) * lastdigit;
        num = num/10;
        counter--;  
    }
    return ret;
}
public static void reverse(int number) {
    while (number != 0) {
        int remainder = number % 10;
        System.out.print(remainder);
        number = number / 10;
    }

    System.out.println();
}

What this does is, strip the last digit (within the 10s place) and add it to the front and then divides the number by 10, removing the last digit. 它的作用是,去除最后一个数字(在10s内)并将其添加到前面,然后将数字除以10,删除最后一个数字。

import java.util.Scanner;

public class ReverseOfInteger {
    static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        int x = input.nextInt();
        System.out.print(helpermethod(x));
    }

    public static String helpermethod(int x) {
        if (x == 0)
            return "";
        String a = String.valueOf(x % 10);
        return a + helpermethod(x / 10);

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM