zoukankan      html  css  js  c++  java
  • Hello,World

    题目:

    1 public class text {
    2     public static void main(String[] args) {
    3         if ( 你的代码 )
    4             System.out.print("hello ");
    5         else 
    6             System.out.println("world");
    7     } 
    8 }

      能使他打印“hello world” 。

      

      可使用的方法如下:

      (一)使用匿名内部类:

    1 public class HelloWorld {
    2     public static void main(String... a) {
    3        if (new Object(){{System.out.print("Hello,");}} == null) {
    4            System.out.print("Hello,");
    5        } else {
    6            System.out.println("World");
    7        }
    8     }
    9 }

      (二)利用PrintStream的append或format等方法(append处改为format):

    1 public class HelloWorld {
    2     public static void main(String... a) {
    3        if (System.out.append("Hello,") == null) {
    4            System.out.print("Hello,");
    5        } else {
    6            System.out.println("World");
    7        }
    8     }
    9 }

      (三)利用反射调用System.out.print 

    public class text {
        public static void main(String[] args) throws Exception {
            if ( System.out.getClass().getMethod("print",String.class).invoke(System.out, "Hello ")!=null)
                System.out.print("hello ");
            else 
                System.out.println("world");
        } 
    }

      (四)利用jdk1.5的printf方法 

    1 public class HelloWorld {
    2     public static void main(String... a) throws Exception {
    3        if (System.out.printf("Hello,") == null) {
    4            System.out.print("Hello,");
    5        } else {
    6            System.out.println("World");
    7        }
    8     }
    9 }

      

  • 相关阅读:
    基于Lucene/XML的站内全文检索解决方案
    内容管理系统(CMS)的设计和选型
    Lucene入门与使用[转]
    为自己的系统搞个全文搜索 参考值:2 (转)
    C# 时间函数
    Lucene倒排索引原理(转)
    什么是内容管理系统CMS?
    网络测试常用命令
    C#与C的区别
    人生致命的八个经典问题
  • 原文地址:https://www.cnblogs.com/jbelial/p/3067471.html
Copyright © 2011-2022 走看看