给定1-n个位置,奇数为比前面的偶数位多+3 , 偶数位比前面的奇数位 +4 , 指定了第一位的大小,问第n位多少。

    xiaoxiao2022-07-05  161

    给定1-n个位置,奇数为比前面的偶数位多+3 , 偶数位比前面的奇数位 +4 , 指定了第一位的大小,问第n位多少。

    //给定1-n个位置,奇数为比前面的偶数位多+3 , 偶数位比前面的奇数位 +4 , 指定了第一位的大小,问第n位多少。 public class SuanFa2 {     public static void main(String[] args) {         System.out.println(getn(10, 3));     }          public static long getn(int first,int n) {         if(n==1) {             return  first;         }         if(n%2==0) {             return getn(first, n-1)+4;         } else {             return getn(first, n-1)+3;         }     }      }

     

    最新回复(0)