算法4 练习1.1.21 递归输入输出

题目:编写一行程序,从标准输入行读取数据,其中每行都包含一个名字和两个整数,然后用printf()打印一张表格。

对于这道题目 我没有完全按照题目要求 只是递归读取数据,我想采用,每次都能一次性输入数据后 再一次性打印出来 

public class test_1_1_21 {
    public static void main(String[] args)throws IOException {
          test_1_1_21.myprint(1);
    }
    public static void myprint(int tag) throws IOException {
        if(tag==0){
            return ;
        }
          System.out.println("input your name and cs score,math score ");
          BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
          String name;
          int csscore,mathscore;
          name = input.readLine();
          csscore = Integer.parseInt(input.readLine());
          mathscore = Integer.parseInt(input.readLine());
          System.out.println("input 1 for continue 0 for exit");
          tag = Integer.parseInt(input.readLine());
          //递归调用
          myprint(tag);
          //结束输出结果
          System.out.println("name is "+name+"cs score is "+csscore+"math score is "+mathscore);
    }
}

下面是函数调用的过程,函数的递归调用过程 就是入栈出栈的过程,当先调用第一个函数的时候

第一个函数入栈 但是此时又调用第二个函数,第二个函数入栈,第一个函数暂时无法执行完毕,等待第二个函数调用完毕出栈才能继续调用第一个函数,以此类推。

最后一个函数调用完毕,出栈。此时倒数第二个函数继续输出 然后调用完毕 接着倒数第三个 输出结果 。。。以此类推。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值