if (条件)  { System.out.println("Hello");  }else{   System.out.println("World");
}
只可以在条件里打代码 要求输出
Hello World

解决方案 »

  1.   

    好像是  java解惑 里面的题目吧
      

  2.   

     if (new Func<bool>(() => { Console.Write("Hello "); return false; }).Invoke())
    {
        Console.WriteLine("Hello ");
    }
    else
    {
        Console.WriteLine("world!");

      

  3.   

    public class Test {
    public static void main(String[] args)  {
    if(System.out.append("Hello ") == null) {
    System.out.println("Hello");
    } else {
    System.out.println(" world");
    }
    }
    }public class Test {
    public static void main(String[] args)  {
    if(new Object(){{System.out.print("Hello ");}}.equals("")) {
    System.out.println("Hello");
    } else {
    System.out.println("world");
    }
    }
    }public class Test {
    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");    

    }
    }public class Test {
    public static void main(String[] args)  throws Exception {
    if(args.length == 0 ? Test.class.getDeclaredMethod("main",args.getClass()).invoke(new Test(), new Object[]{new String[]{"a"}}) != null : true){  
                System.out.print("Hello ");  
            }else{  
                System.out.println("world");  
            }  
    }
    }
    public class Test {
    public static void main(String[] args) throws Exception {
    if (args == null ? true : ((Test.class.getMethod("main", new String[1].getClass()).invoke(new Test(),
    new Object[1])) instanceof Void)) {
    System.out.print("Hello ");
    } else {
    System.out.println("world");
    }
    }
    }
      

  4.   

    http://www.javaeye.com/topic/781849
      

  5.   

    学习下,lamada表达式,这个问题就迎刃而解了