开发者社区 问答 正文

如何编写一个可以输出自己源代码的程序?

如何编写一个可以输出自己源代码的程序,要满足以下要求:
1.该程序不可以从外部读取输入。
2.该程序的输出不可以为空。
想了很久始终无法想明白要如何做到

展开
收起
蛮大人123 2016-03-06 18:11:35 2917 分享 版权
2 条回答
写回答
取消 提交回答
  • 不明白你的意思,用ide集成开发环境就可以写你的源码

    2019-07-17 18:55:01
    赞同 展开评论
  • 我说我不帅他们就打我,还说我虚伪
    public class Quine
    {
      public static void main(String[] args)
      {
        char q = 34;      // Quotation mark character
        String[] l = {    // Array of source code
        "public class Quine",
        "{",
        "  public static void main(String[] args)",
        "  {",
        "    char q = 34;      // Quotation mark character",
        "    String[] l = {    // Array of source code",
        "    ",
        "    };",
        "    for(int i = 0; i < 6; i++)           // Print opening code",
        "        System.out.println(l[i]);",
        "    for(int i = 0; i < l.length; i++)    // Print string array",
        "        System.out.println(l[6] + q + l[i] + q + ',');",
        "    for(int i = 7; i < l.length; i++)    // Print this code",
        "        System.out.println(l[i]);",
        "  }",
        "}",
        };
        for(int i = 0; i < 6; i++)           // Print opening code
            System.out.println(l[i]);
        for(int i = 0; i < l.length; i++)    // Print string array
            System.out.println(l[6] + q + l[i] + q + ',');
        for(int i = 7; i < l.length; i++)    // Print this code
            System.out.println(l[i]);
      }
    }
    2019-07-17 18:55:00
    赞同 展开评论
问答地址: