基本就是这个思路了呵呵import java.util.Scanner;public class DiGui {
public static void main(String[] args) {
int x = 1, y;
String str ="";
Scanner scan = new Scanner(System.in);
y = scan.nextInt();
while(x < y){
str += x + "-";
System.out.println(str + y);
x++;
}
}
}

解决方案 »

  1.   

    昨天写的方法是用循环解决的
    修改了一下改成递归方式的import java.util.Scanner;public class DiGui {
    static String str ="";
    public static void main(String[] args) {
    int x = 1, y;
    // String str ="";
    Scanner scan = new Scanner(System.in);
    y = scan.nextInt();
    // while(x < y){
    // str += x + "-";
    // System.out.println(str + y);
    // x++;
    // }
    digui(x, y);
    }
    public static int digui(int x, int y){

    if(x == y){
    return x;
    }else{
    str += x + "-";
    System.out.println(str + y);
    return digui(x + 1, y);
    }
    }
    }
      

  2.   

    不好意思 没看到1-3-4
    不过问题已经解决了
    循环 递归都有
    地址http://topic.csdn.net/u/20090206/20/424a71c7-add4-4e55-93c6-67fa395e6931.html?seed=232714305