public class Change { public static void main(String[] args) {
int []istr = {0,4,5,6};
changing(istr);

}

public static void changing(int[] istr){

int old1 = 0,old2 = 0,old3 = 0,old4 = 0;
int first = 0,secend = 0,third = 0,forth = 0;
first = istr[0];
secend = istr[1];
third = istr[2];
forth = istr[3];

if (first >= 5)
{
old4 = first - 5;
}else 
{
old4 = first + 5;
}

if (secend >= 5)
{
old3 = secend - 5;
}else 
{
old3 = secend + 5;
}

if (third >= 5)
{
old2 = third - 5;
}else 
{
old2 = third + 5;
}

if (forth >= 5)
{
old1 = forth - 5;
}else 
{
old1 = forth + 5;
}

System.out.println("jiami hou shuju is " + first  + " " + secend + " " + third + " " + forth);
System.out.println("jiami qian shuju is " + old1 + " " + old2 + " " + old3 + " " + old4);

}
刚写的老大。。
给你写了好几个了。

解决方案 »

  1.   

    晕,四楼把这么简单的问题写这么复杂public class Change {
        public static void main(String[] args) {
            int []istr = {0,4,5,6};
            istr = changing(istr);
        }
        
        public static int[] changing(int[] istr){
          if(istr == null || istr.length != 4){
            return null;
          }
          
          int[] ret = new int[4];
          for(int i=0; i<4; i++){
            ret[3-i] = (istr[i]+5)%10;
          }
          return ret;
        }
    }
      

  2.   


    public class NumChange {  int []arrayLock;
     int []arrayUnLock;
     public NumChange()
     {
     }
     public void Lock(int[]array){
     arrayLock = new int[array.length];
     for(int i = 0; i< array.length; i++){
     array[i]+= 5;//每位加5
     array[i] = array[i] % 10;//加5后的和除以10
     }
     for(int i = 0; i< array.length ; i++){
     arrayLock[i] = array[array.length - i -1];
     }
     }
     public void UnLock(int[]array){
     arrayUnLock = new int[array.length];
     for(int i = 0; i< array.length; i++){
     if(array[i] >= 5){
     array[i]-= 5;
     }
     else{
     array[i]+= 5;
     }
     }
     for(int i = 0; i< array.length ; i++){
     arrayUnLock[i] = array[array.length - i -1];
     }
     }
    public static void main(String[] args) {

    //随机产生一些数
    int nCount = 4;
    int []array  = new int[2* nCount];
    for(int i = 0;i < array.length;  ){
    int n = (int)(Math.random()*10);
    if(n <= 9 && n >= 0){
    array[i] = n;
    i++;
    }
    }

    NumChange change = new NumChange();
    System.out.print("原始数据:");
    for(int i = 0;i < array.length; i++){
    System.out.print(array[i]);
    }
    System.out.println("");
    //加密
    change.Lock(array);
    System.out.print("加密后:");
    for(int i = 0; i < array.length; i++){
    System.out.print(change.arrayLock[i]);
    }
    System.out.println("");
    //解密
    change.UnLock(change.arrayLock);
    System.out.print("解密后:");
    for(int i = 0; i < array.length; i++){
    System.out.print(change.arrayUnLock[i]);
    }
    }}
      

  3.   

    我是个新手,刚写好的,不知道行不?
    问下大家,我贴上去的代码格式怎么都变了。都没有缩进?怎么才能像你们的一样?我在eclipse里都是有缩进的,怎么拷贝出来贴在这就变了?谢谢