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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

package ifjg;
public class Tex {
public static void main(String[] args) {
   if(___________){
    System.out.println("world");
   }
   else{
    System.out.println("hello");
   }
}
}
只能在if(_____)里面写代码,如何让输出结果是“hello world”?

点评

if(System.out.printf("hello ")!=null){ System.out.println("world"); } else{ System.out.println("hello"); } 百度出来的   发表于 2012-11-30 20:42
随便填一个让条件不成立就行了啊  发表于 2012-11-30 18:33

评分

参与人数 2技术分 +2 收起 理由
杨千里 + 1 有点技术含量...
古银平 + 1 神马都是浮云

查看全部评分

14 个回复

正序浏览
杜正冬 发表于 2012-11-30 18:58
if(true){
                        System.out.println("hhhhhh");
                }else {

难道我这个错了么  不也可以打印么
回复 使用道具 举报
难道我的不对???我运行了 可以打印啊
回复 使用道具 举报
tfy 中级黑马 2012-11-30 23:25:46
13#
        public static void main(String[] args) {
                   if(System.out.printf("hello") != null){
                    System.out.println("world");
                   }
                   else{
                    System.out.println("hello");
                   }
                }
回复 使用道具 举报
应文 中级黑马 2012-11-30 22:34:39
12#
print没有返回值,printf是新版本中的格式化输出,返回值是PrintStream类型。
回复 使用道具 举报
经测试。public static void main(String[] args) {

                     if(!System.out.printf("hello ").equals("")){
                      System.out.println("world");
                     }
                     else{
                      System.out.println("hello");
                     }
                     if(System.out.printf("hello ")!=null){
                              System.out.println("world");
                             }
                             else{
                              System.out.println("hello");
                             }
                }
这两种都可以
回复 使用道具 举报
魏冬 中级黑马 2012-11-30 21:27:11
10#
应文 发表于 2012-11-30 19:52
public static void main(String[] args) {
     if(!System.out.printf("hello ").equals("")){           ...

你的这个printf 是什么意思?
回复 使用道具 举报
马磊 中级黑马 2012-11-30 20:55:53
9#
题目考验人啊,在if的判断语句里输出hello,和后面else里的hello就没有关系
回复 使用道具 举报
应文 中级黑马 2012-11-30 20:50:08
8#
{:soso_e100:}
回复 使用道具 举报
应文 中级黑马 2012-11-30 19:52:32
7#
本帖最后由 应文 于 2012-12-1 21:43 编辑

public static void main(String[] args) {
     if(!System.out.printf("hello ").equals("")){           //这样
      System.out.println("world");
     }
     else{
      System.out.println("hello");
     }
  }


我是这么想的,不对的地方请多多指教:{:soso_e100:}
1:if语句不能循环判断两次,也就是说不可能先if判断条件语句1,执行if结束后,再重新判断这个if的条件语句2。
2:毕老师视频,for循环(第三天第5节视频),说可以在条件语句中用输出语句,我分析在视频中因为在for条件语句中不需要对使用的输出语句进行判断,而是只输出abc,所以可以使用println、print和printf,但是这里的if语句在我们填上一个条件语句后需要判断是真或是假,必须输出个hello,并且判断,而println、print、printf中只有printf是有返回值的(PrintStream类型),所以这里只能填printf了,至于后面的判断,如版主杨千里版主说的直接判断!=null也行,我之所以这么写,是因为我原先是想与args比较判断的。

评分

参与人数 1技术分 +1 收起 理由
古银平 + 1 为什么是这样?

查看全部评分

回复 使用道具 举报
本帖最后由 王震阳 于 2012-11-30 19:44 编辑

对不起啦,网速卡了,导致重复回复那么多。
回复 使用道具 举报
版主有点轻看楼主的题目了吧,随便填写一个false是不行的。
回复 使用道具 举报
本帖最后由 王震阳 于 2012-11-30 19:45 编辑

这个题自己也不会呀。希望大家能写出答案。
回复 使用道具 举报
版主有点请看楼主的题目了吧,随便填写一个false是不行的。
回复 使用道具 举报
if(true){
                        System.out.println("hhhhhh");
                }else {
                        System.out.println("00000");
                }
               
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马