A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 迷茫不堪的年纪 金牌黑马   /  2015-9-21 20:14  /  2132 人查看  /  36 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

其中错误千千万哦, 小牛们可以找出多少啊?
1>
***
***
****
*****
目标:使用for 循环打印处以上符号
class ForForTest1
{
public static void main(String[]args)
{
for(ing x=1;x<=5;x++);
{
for(int y=1;y<=x;y++);
}
System.out.print("x="+x);
}
System.out.println();
}
疑问点:当X<=时 ,y是否也是正常<=          ?

2>
*****
****
***
**
*
目标:使用for 循环打印处以上符号
方法1:
class ForForTest2
{
public static void main(String[]args)
{
for(ing x=0;x<5;x++);
{
for(int y=x;y<5;y++);
}
System.out.print("x="+x);
}
System.out.println();


方法2:
class ForForTest3
{
public static void main(String[]args)
{
for(ing x=0;x<5;x++);
{
for(int y=0;y<5;y--);
}
System.out.print("x="+x);
}
System.out.println();

}

3>九九乘法表
1*1=1
1*2=2   以此类推,九九乘法
class ForForTest4
{
public static void main(String[]args)
{
for(ing x=1;x<=9;x++);
{
for(int y=1;y<=x;y++);
}
System.out.print(x+“*”+y“=”x*y"\t");
}
System.out.println();

}
4>
1
12
123
1234
12345
class ForForTest5
{
public static void main(String[]args)
{
for(ing x=0;x<5;x++);
{
for(int y=1;y<=5;y++);
}
System.out.print(y);
}
System.out.println();

}


6>1-10的求和
0+1=1
1+2=3
规律如此
class ForForTest6
{
public static void main(String[]args)
{  int sum=0    //定义不断变化的和
for(ing x=0;x<=10;x++);
{
sum+=sum;
System.out.printlny(“sum=”+sum);
}

}

}

7>1-100 中7的个数
class ForForTest7
{
public static void main(String[]args)
{
int  count=0;
for(ing x=1;x<=100;x++);
{
if(x%7=0)
{
System.out.println("count="+count);
}
}
}
}



8>
*   *   *   *    *
   *    *   *   *
     *    *   *
       *    *
          *
目标:使用for 循环打印处以上符号
class ForForTest8
{
public static void main(String[]args)
{
for(ing x=1;x<=5;x++);
{
for(int y=x;y<x;y++); // 打出空格
{
System.out.print(“ ”)
}
for(int z=x;z<=5;z++)
{
System.out.print(“* ”)//打*
}
System.out.println();

}
}
}


36 个回复

倒序浏览
错误这么多呢,  能找多少呢?
回复 使用道具 举报 1 0
看不懂啊这个
回复 使用道具 举报
能插入代码的 你这排版 根本看不下去
回复 使用道具 举报
这代码简直没办法看。 没缩进。
回复 使用道具 举报
这第一个打印的全是数字,和*这个符号没关系啊。代码看不懂
回复 使用道具 举报
这代码看的头晕
回复 使用道具 举报
太6、、、
回复 使用道具 举报
脑袋都看晕咯
回复 使用道具 举报
没有缩进,看的头都大了
回复 使用道具 举报
自我报错, 1. 符号错误,  因较少发帖, 所以直接在帖子上输入了, 观看性确实比较差。
回复 使用道具 举报
lanyu 中级黑马 2015-9-21 22:03:20
12#
1>   
     /*
* 打印正 如下的形状
*     *
*     **
*     ***
*     ****
*     *****
*
*/
// 需求分析:打印4行5列的*
//思路:用嵌套for循环实现多行多列的功能,外层for控制行数,内层for控制列数
public class demo {
  public static void main(String[] args) {
        for(int x=1;x<6;x++) {
                for(int y=0;y<x;y++) {
                        System.out.print("*");
                }
                System.out.println(" ");
        }
}
}

点评

亲,个人感觉,首先我之前是代码是代码其实是错误的, 但是既然是4行5列。1.2.3.4.5 是5行了哦, 个数之后也出现问题了哦  发表于 2015-9-21 23:09
回复 使用道具 举报
本帖最后由 年年糕v 于 2015-9-21 22:12 编辑

第二题的方法一正确版本!!
//目标:使用for 循环打印处以上符号
//方法1:
class ForForTest2
{
public static void main(String[]args)
        {
                for (int x =0;x<5 ;x++ )
                {
                        for (int y=x;y<5;y++ )
                        {
                                System.out.print("*");
                        }
                        System.out.println();
                }
    }
}
第二题 方法二的正确方法
//目标:使用for 循环打印处以上符号
//方法2:
class ForForTest3
{
public static void main(String[]args)
        {
                for (int x =0;x<5 ;x++ )
                {
                        for (int y=5;y>x;y-- )
                        {
                                System.out.print("*");
                        }
                        System.out.println();
                }
    }
}


点评

小重点在于:for (int y=5;y>x;y-- ) //定义个数从5开始一个一个递减  发表于 2015-9-21 23:04
回复 使用道具 举报
太溜,流的不行了.............
回复 使用道具 举报
xiaoya0o0o 发表于 2015-9-21 22:09
太溜,流的不行了.............

都是乱搞的。 其实你都可以看懂的, 一个个看
回复 使用道具 举报
路过,顶一下
回复 使用道具 举报

是个循环, 太乱了
回复 使用道具 举报
洋葱头头 发表于 2015-9-21 20:28
能插入代码的 你这排版 根本看不下去

嘿嘿, 求教啊。。。。很少发帖
回复 使用道具 举报
脑壳疼。。。。。。。。
回复 使用道具 举报
看的费劲
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 加入黑马