大神帮忙 FOR循环

m0_38089532 2017-03-27 09:42:10
class Demo_Zuoye {
public static void main(String[] args) {
for(int i=1;i<100;i++){
if((i==9||i%10==9))
continue;
for(int i1=0;i1<5;i1++){

System.out.print(i+" ");

}
System.out.println();
}
为什么每个数字要重复5遍?而不是以此输入1 2 3 4 5再换行输出 6 7 8 10 11?
1 2 3 4 5
6 7 8 10 11
12 13 14 15 16
...全文
472 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
galiniur0u 2017-03-28
  • 打赏
  • 举报
回复
不知道是不是跟楼主的需求一致。 实现功能,过滤掉个位数为9的数字,每行输出5个值,每个值之间使用空格分隔。

		for(int i = 1, k = 1; i < 100; i ++){
			if(i % 10 == 9){
				continue;
			}else{
				System.out.print(String.format("%02d ", i));
			}
			if(k % 5 == 0){
				System.out.println();
			}
			k ++;
		}
qq609737607 2017-03-28
  • 打赏
  • 举报
回复
输出结果为 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 50 51 52 53 54 55 56 57 58 60 61 62 63 64 65 66 67 68 70 71 72 73 74 75 76 77 78 80 81 82 83 84 85 86 87 88 90 91 92 93 94 95 96 97 98
qq609737607 2017-03-28
  • 打赏
  • 举报
回复
这个应该是你要的 package project0327; /** * 求出100以内的没有9的数,并且已5位数一行的排列出来 * * * */ public class Text1 { public static void main(String[] args) { int a=0; for(int i=0;i<100;i++){ if(i%10!=9){ System.out.print(i+" "); a++; }if(a%5==0){ System.out.println(); } } } }
zs808 2017-03-28
  • 打赏
  • 举报
回复
或者这么写:

for (int i = 1; i < 100; i+=5) { //这里,i递增5
			if ((i == 9 || i % 10 == 9))
				continue;
			for (int i1 = 0; i1 < 5; i1++) {

				System.out.print(i1 + i + " "); //这里,改成i1+i

			}
			System.out.println();
		}
感觉这样应该比较符合lz的本意
zs808 2017-03-28
  • 打赏
  • 举报
回复
更正下: 改成:

System.out.print(i1 + (i - 1) * 5 + 1 + " ");
zs808 2017-03-28
  • 打赏
  • 举报
回复
lz犯了一个比较“低级”的错误哈。

System.out.print(i + " ");
这句,应该是

System.out.print(i1 + i + " ");
才对。
peisir888 2017-03-27
  • 打赏
  • 举报
回复
class Demo_Zuoye { public static void main(String[] args) { int a=0 for(int i=1;i<100;i++){ a++; if((i==9||i%10==9)) {i+=1;} System.out.print(i+" "); System.out.println(); } System.out.println(); } } } 不要用continue;continue会让for循环跳出
shuwenawe 2017-03-27
  • 打赏
  • 举报
回复
你的if (i == 9|| i %10 == 9)判断条件有重复了吧,9 % 10也为9
m0_38089532 2017-03-27
  • 打赏
  • 举报
回复
输出来了但是输出的是 12345 6 7 8 10 11 12 13 14 15 16 17 18 20 碰到5的倍数就换行 但是6到10才4个数 不是5个数 我要的是 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 ...
m0_38089532 2017-03-27
  • 打赏
  • 举报
回复
class Demo_Zuoye { public static void main(String[] args) { for(int i=1;i<100;i++){ if((i==9||i%10==9)) continue; System.out.print(i+" "); int count=0; if(count%5==0){ System.out.println(); } count++; } //System.out.println("Hello World!");//9 19 29 39 49 59 69 79 89 90 91 92 93 94 } } 为什么不换行?而且又输出了90以上的数字
shazhiwuzhe 2017-03-27
  • 打赏
  • 举报
回复
public class Test { public static void main(String[] args) { int count =0; for(int i=1;i<100;i++){ if((i==9||i%10==9)){ continue; }else{ System.out.print(i+" "); count++; if(count%5==0){ System.out.println(); } } } } }
李德胜1995 2017-03-27
  • 打赏
  • 举报
回复
引用 2 楼 m0_38089532 的回复:
循环去掉?抱歉 不会弄那个啊

int count=1;
		for(int i=1;i<100;i++){
			if((i==9||i%10==9))
			continue;
			System.out.print(i+" ");
			if(count%5==0){
				System.out.println();
			}
			count++;
		}

m0_38089532 2017-03-27
  • 打赏
  • 举报
回复
循环去掉?抱歉 不会弄那个啊
李德胜1995 2017-03-27
  • 打赏
  • 举报
回复
for(int i1=0;i1<5;i1++)循环去掉,加入一个变量。。。每次循环加一,判断是否是5的倍数在使用System.out.println();换行

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧