【C#】考你一个输出“Hello World”程序

aimeast 2010-10-09 08:48:30
加精
前天同学问我这样一个面试题:完成如下代码,使其输出“Hello World!”
if() printf("Hello");
else printf(" World!");
我很快想到了答案。然后同学告诉我这个题不止一个答案。

如果换成C#,也可以这样问:完成如下代码,使其输出“Hello World!”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
if (/* 补充这里 */)
Console.Write("Hello");
else
Console.Write(" World!");
}
}
}
用C#语言,至少我已经想到了三种不同原理的答案。

欢迎大家想出更多的答案。

我会在若干天以后公布我所想到的答案。
...全文
24612 720 打赏 收藏 转发到动态 举报
写回复
用AI写文章
720 条回复
切换为时间正序
请发表友善的回复…
发表回复
chuan1985 2013-07-01
  • 打赏
  • 举报
回复
各有千秋!!!!!
  • 打赏
  • 举报
回复
敌敌畏耶 2013-06-25
  • 打赏
  • 举报
回复
貌似答案很多啊· 第一:你的if里面的为false 第二:你的if里面的必须有输出 helle 只要满足就两点就行了啊···
Snial-lns 2013-03-13
  • 打赏
  • 举报
回复
牛人呀 学习一下
huangjing1994219 2013-03-13
  • 打赏
  • 举报
回复
九九歌神 2013-03-13
  • 打赏
  • 举报
回复
引用 154 楼 xp200798 的回复:
感觉实在很没必要写得那么复杂……而且觉得这题目很无用…… C++和C#都贴出来 C/C++ code?123456789#include "stdafx.h"#include <stdio.h> int main(int argc, char* argv[]){ if(printf("Hello") && 0) printf("Hello……
实现不了。。。
九九歌神 2013-03-13
  • 打赏
  • 举报
回复
引用 147 楼 yang120989 的回复:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HelloWorld { class Program { static void Main(string[] args) ……
不可以,写的有问题,加上括号后也只是输出hellohello,把!去掉可以。
hoho0326077 2013-03-07
  • 打赏
  • 举报
回复
我是被27#牛到了
whm412 2013-03-05
  • 打赏
  • 举报
回复
贴子没全部看完,但发现大神还是很多啊。
xiaoxiyang09 2013-02-28
  • 打赏
  • 举报
回复
很给力 看了很多种解决方法 受教了
SharpUrMind 2013-02-27
  • 打赏
  • 举报
回复
不错的帖子,拓宽了思维~~~
w2579194474 2013-02-20
  • 打赏
  • 举报
回复
看了,忍不住顶下……
CalmOrz 2013-01-11
  • 打赏
  • 举报
回复
引用 27 楼 baihacker 的回复:
C# code?123456789101112131415161718using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace HelloWorld{ class Program { static void Main(s……
这、、、
蛮大人LT 2012-12-19
  • 打赏
  • 举报
回复

if (true)Console.Write("Hello World");//)
else
  Console.Write(" World!");

>>>>>>>>>>>>>>>>>>>>> 灵感来自sql 注入 请评价 >>>>>>>>>>>>>>>>>>>>>
nayu139 2012-12-17
  • 打赏
  • 举报
回复
受教了
peng93 2012-12-08
  • 打赏
  • 举报
回复
我今天又学了一招
y1021347555 2012-12-05
  • 打赏
  • 举报
回复
好帖 一句Hello Word!引发的血案
xy3126088 2012-11-07
  • 打赏
  • 举报
回复
在判断的时候输出hello 然后加上 &&(一个为False的条件)走else语句吧
gyk_net 2012-11-04
  • 打赏
  • 举报
回复
牛人真多啊·····
wangyd324 2012-11-01
  • 打赏
  • 举报
回复
mark
加载更多回复(647)

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧