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

© 张明 中级黑马   /  2012-8-13 20:53  /  2083 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. class dengyao
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 for(int x=1;x<=5;x++)
  6.                 {
  7.                         for(int y=1;y<x;y++)
  8.                         {
  9.                                 System.out.print(" ");
  10.                         }
  11.                         for(int z=x;z>0;z--)
  12.                        {
  13.                                 System.out.print("* ");
  14.                         }
  15.                 }
  16.                  System.out.println();
  17.          }
  18. }
复制代码
运行时显示:找不到或无法加载主类。
这问题之前一直没遇到过啊,做练习一直也没问题的,现在写程序就突然出现这个问题了
求解释

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

6 个回复

正序浏览
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("给我一个奇数");
            int arr = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < (arr+1)/2; i++)
            {
                string line = "";
                for (int j = 0; j < arr; j++)
                {
                    
                    if (j <= (i - 1) || j > (arr-1- i))
                    {
                        string b = " ";
                        line = line + b;
                    }
                    else
                    {
                        string c = "*";
                        line = line + c;
                    }
                    
                }
                Console.WriteLine(line);
            }
            Console.ReadKey();
        }
    }
新人分享,各位高手牛人们看看,分析一下怎么样

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

回复 使用道具 举报
严学韦 发表于 2012-8-13 22:31
1.找不到主类是因为类名打错了,小问题,仔细点看看类名就明白了
2.楼主代码运行结果也是有问题的,输出的 ...

谢谢你的帮助,自己更改后已成功运行
回复 使用道具 举报
郑小杰 发表于 2012-8-13 21:33
  • class dengyao
  • {
  •         public static void main(String[] args)

  • 谢谢帮助,自己更改后已成功运行
    回复 使用道具 举报
    本帖最后由 严学韦 于 2012-8-13 22:38 编辑

    1.找不到主类是因为类名打错了,小问题,仔细点看看类名就明白了
    2.楼主代码运行结果也是有问题的,输出的不是等腰三角形哦,所以下面的代码稍有修改
    3.建议楼主将类定义为ShapeDemo,将DengYao定义为ShapDemo中的方法
       一开始养成命名规范的好习惯很重要,下面是供楼主参考的代码
    1. class ShapeDemo
    2. {
    3.         public static void main(String[] args)
    4.         {
    5.                DengYao();  
    6.         }

    7.         public static void DengYao()//静态方法DengYao
    8.         {
    9.                for(int x=1;x<=5;x++)//控制行
    10.                 {
    11.                for(int y=0;y<5-x;y++)
    12.                  {
    13.                        System.out.print(" ");
    14.                  }
    15.                for(int z=x;z>0;z--)
    16.                  {
    17.                        System.out.print("* ");
    18.                  }
    19.                System.out.println();//换行
    20.                }               
    21.          }
    22. }
    复制代码
    运行结果:

    运行结果.jpg (4.63 KB, 下载次数: 65)

    运行结果.jpg

    评分

    参与人数 1技术分 +1 收起 理由
    郑文 + 1

    查看全部评分

    回复 使用道具 举报
    • class dengyao
    • {
    •         public static void main(String[] args)
    •         {
    •                 for(int x=1;x<=5;x++)
    •                 {
    •                         for(int y=0;y<5-x;y++)//这里帮你改了
    •                         {
    •                                 System.out.print(" ");
    •                         }
    •                         for(int z=x;z>0;z--)
    •                        {
    •                                 System.out.print("* ");
    •                         }
    •                 }
    •                  System.out.println();
    •          }
            }
    找不到或无法加载主类,这个是因为你运行的时候把类名字敲错了,呵呵,还有,你的代码帮你改了,你在看看

    评分

    参与人数 1技术分 +1 收起 理由
    郑文 + 1

    查看全部评分

    回复 使用道具 举报
    对不起,新手第一次发帖,发错地方了
    回复 使用道具 举报
    您需要登录后才可以回帖 登录 | 加入黑马