基本就是这个思路了呵呵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++;
}
}
}
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++;
}
}
}
解决方案 »
- 用java如何添加附件到excel中
- EXT为啥没有下拉多选呢?
- html脚本存入oracle 数据库 报错!!急
- java程序备份恢复mysql数据库问题.急!!!求解!!!
- 我用STRUTS2 做的网站 <welcome-file>是个空页面跳转到一个action 然后在转到首页 对SEO有没影响?
- axis webservice生成wsdl文件问题
- xslt 问题
- java银行接口调用商家,商家怎么通知银联数据更新好了,叫银联停止调用商家后台更新数据接口
- 数据刷新问题,我的MIS系统!
- 谁能给一个把数据库中的String(xml文档)类型取出解析成XML Document的例子?
- struts 操作数据库时出异常(oracle 9i) 我是新手 刚刚自学这个 希望各位高手给予指点 谢谢
- 有没朋友推荐下工作
修改了一下改成递归方式的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);
}
}
}
不过问题已经解决了
循环 递归都有
地址http://topic.csdn.net/u/20090206/20/424a71c7-add4-4e55-93c6-67fa395e6931.html?seed=232714305