1. 程式人生 > >打印begin~end

打印begin~end

stat logs sca 打印 clas class () dem -1

要求:

  輸入:begin和end

  輸出:依次打印出begin到end

  

 1 import java.util.Scanner;
 2 //遞歸打印begin —— end
 3 public class demo1 {
 4 
 5     public static void f(int begin,int end){
 6         if(end-1>=begin){
 7             f(begin,end-1);
 8         }
 9         System.out.print (end+" ");
10     }
11     public
static void main(String[] args) { 12 Scanner sc = new Scanner(System.in); 13 int begin = sc.nextInt(); 14 int end = sc.nextInt(); 15 f(begin,end); 16 } 17 18 }

打印begin~end