解题思路:
使用递归方法进行求解
注意事项:
递归方法之中注意代码顺序
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] tem = new int[100]; int i=0; while(sc.hasNext()){ int m=sc.nextInt(); if(m==0){ break; }else{ tem[i++]=m; } } int[] tem2 = new int[i]; for(int a=0;a<i;a++){ tem2[a]=tem[a]; } for (int i1 = 0; i1 < tem2.length; i1++) { System.out.println(compute(tem2[i1])); } } private static int compute(int i) { if(i==2||i==3){ return 1; } int sum=0; sum+=i/3; return sum+=compute(i%3+i/3); } }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题12.1 (C语言代码)浏览:982 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:512 |
【亲和数】 (C语言代码)浏览:541 |
【亲和数】 (C语言代码)浏览:492 |
字符串问题 (C语言代码)浏览:1506 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:694 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:1091 |
C语言程序设计教程(第三版)课后习题6.5 (C++代码)浏览:449 |
K-进制数 (C语言描述,蓝桥杯)浏览:925 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:485 |