如题

解决方案 »

  1.   

    int n = 2;
    int a=22222;
    a = (int) ((int)(a/Math.pow(10,n))*Math.pow(10,n)+(int)Math.pow(10,n-1)+(int)(a%Math.pow(10,n-1)));
      

  2.   


    public static void main(String[] args) {
    int a = 123456789;
    int change = 1;
    int index = 3;
    String str = String.valueOf(a);
    int other = Integer.parseInt(str.substring(0, index) + change + str.substring(index + 1));
    System.out.println(other);
    }
      

  3.   

    public static void main(String []  args){
              System.out.println("input your num:");
           Scanner scan=new Scanner(System.in);
           String a=scan.next();
           StringBuffer str_1=new StringBuffer(a);
           System.out.println("指定你要修改的位置:");
           Scanner read=new Scanner(System.in);
           int n=read.nextInt();
           str_1.setCharAt(n-1,'1');
           System.out.print(str_1);
          }
      

  4.   


    public class Test {
    public static void main(String[] args) {
    System.out.println(replace(123456789, 4));
    }

    static int replace(int n,int index){
    String string = String.valueOf(n);
    return Integer.valueOf(string.replace(string.charAt(index - 1), '1')
    }
    }
      

  5.   

    想法是吧a变成string然后再去替换在转化回INT
      

  6.   

    有问题的。 string.replace(string.charAt(index - 1), '1')慎用
      

  7.   

    的确是有问题,纠正下
    public class Test {
        public static void main(String[] args) {
            System.out.println(replace(133334892, 6));
        }
        
        static int replace(int n,int index){
            StringBuffer string = new StringBuffer(String.valueOf(n));
            string.setCharAt(index - 1, '1');       
            return Integer.valueOf(string.toString());      
        }
    }
      

  8.   

    如果给的是整数a,那么结果应该是a|100....(一个N-1个0)int get(int source,int n){
    int result=1;
    while(--n!=0){
    result=result<<1;
    }
    return source|result;
    }
      

  9.   

    转换成字符串,修改之后再转换成int
      

  10.   

    我说的是二进制
    int get(int source,int n){
    return source|(1<<(n-1));
    }这样写速度最快