a=a*10+b型题目

1.反转数字

你输入1478,则得到8741

你输入4567,则得到7654

class Solution
{
  public int Reverse(int n)
  {
      int i=0,result=0;
      while(n!=0)
      {
          //不断的拿出个位
          i=n%10;

          result=(result*10)+i;

          //把个位去除
          n/=10;
      }
      return result;
  }
}

public class demo
{
    public static void main(String[] args)
    {
        Solution solution=new Solution();
        System.out.println(solution.Reverse(123456));
    }
}

2.剑指offer17

力扣

class Solution 
{
    public int[] printNumbers(int n) 
    {
        //输入1,就要到9,输入2,就要到99,输入3,就要到999
        int temp=0;
        for(int i=0;i<n;i++)
        {
            temp=10*temp+9;
        }
        int[] result=new int[temp];
        for(int i=0;i<temp;i++)
        {
          result[i]=i+1;
        }
        return result;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_47414034/article/details/125426835