今天面试的一个题,让我很是无脸见人. for(int i=0;;i++){ console.write(i);}我的回答简直是丢程序员的脸,还是不说了...不知道这里有没人也不知道答案的. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 题都错了for(int i; i=0;;i++){ console.write(i);} TO:题都错了for(int i; i=0;;i++){ console.write(i);}题怎么错了?无非是个死循环而已.... for(int i=0;;i++){ console.write(i);}这个题目也行...差点又马虎. for(int i; i=0;;i++){ console.write(i);}这样编译能通过!是这样的吧?for(int i, i=0;;i++){ console.write(i);} for (int i = 0; ; i++) { Console.Write(i); }无限循环 我来更正一下吧.试题原题目int i;for(i=0;;i++){ }我写成for(int i=0;;i++){ console.write(i);}两种都行...楼上的那样写不能编译. for(int i, i=0;;i++){ console.write(i);}通过不了。没试成功 for(int i, i=0;;i++){ console.write(i);}这个会出错,因为i没有初值for (int i = 0; ; i++) { Console.Write(i); }当超过int的长度会出错,int有多长我忘了-_#基础都跟压饭底了 for(bool i; i=false; i=!i){ Console.Write(i);}这个更有意思。不过在C++中更好玩一点:for(int i; i=0; i++){ cout << i;} for(int i; i=0;;i++){ console.write(i);}for(int i; i=0;;i++)这条语句能行吗?for(int i; 这里要求是一个Bool的;;i++)晕倒,有这个时间发这个贴,为啥不用C#写一个Demo试试看???? 什么题目嘛看不懂,实在看不懂。本人感觉现在招聘方出的题目水平越来越低下了。比如1!+2!+...+n!这样的题目也出来了,没有足够的时间我看人事部的(如果纯嵌套实现)也不能在1个小时内完成。可能是太自大了。下面放我在笔试后的解决代码:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace _1__2____n_{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox2; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.textBox2 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(24, 16); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(128, 21); this.textBox1.TabIndex = 0; this.textBox1.Text = "输入一个自然数"; // // label1 // this.label1.Location = new System.Drawing.Point(32, 48); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(136, 16); this.label1.TabIndex = 1; this.label1.Text = "结果在下面:"; // // button1 // this.button1.Location = new System.Drawing.Point(176, 16); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(80, 24); this.button1.TabIndex = 0; this.button1.Text = "运行"; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox2 // this.textBox2.AutoSize = false; this.textBox2.Location = new System.Drawing.Point(8, 72); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(256, 40); this.textBox2.TabIndex = 3; this.textBox2.Text = ""; // // Form1 // this.AcceptButton = this.button1; this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(280, 118); this.Controls.Add(this.textBox2); this.Controls.Add(this.button1); this.Controls.Add(this.label1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { int i=int.Parse(this.textBox1.Text); this.textBox2.Text=goon(i,i).ToString(); } private int goon(int n,int k) { if(0==k&&0==n)return 1; else { if(0==k) return 0; else if(1==k) { if(1==n)return 1; else return n=n*goon(n-1,k); } else return goon(n,k-1)+goon(n-1,k-1)-goon(n-1,k-2); } } }} 用for(int i=0;;i=i+1000000){ Console.WriteLine(i);}验证为死循环 题很不错的,主要是Int的范围的问题 for(int i=0;;i++){ console.write(i);}死循环,最后会溢出. for(int i=0;true;i++){ Console.Write(i);} 应该是死循环了不过肯定超过int的范围肯定会报错的 for(int i=0;;i++) { Console.Write(i); }这应该时个死循环当int达到最大65536时抛出异常 我试了 就时不抛出异常怎么回事 死循环,不是什么int值范围考察汇编出来都是jmp循环跳转 for(;;){ Console.Write("i");} 做 int i; for(i=0;;i++) { printf("%d\n",i); }从0~32767就转入-32767~0 liyang19860104() 说得对!我刚作过试验! iamcooky(绿蓑衣) 说的对我也得到了同样的数据 TO ttpps() ( ) 信誉:100 Blog 回去好好学学数学好吗?基本的数学公式你不知道?要是出1+2---------+N的话估计你就会知道了 for (int i = 0; ; i=i+65535) { Console.write(i); }不会有溢出,省略第二条件,第二条件黑认为True;所以死循环。不过还是觉得出题的人有点白痴变态。 靠,二楼吓我一大跳!还以为for里面可以使用三个冒号! 看了楼主的题目想起来一道题 是去年面试的时候在a.spx文件中有一段脚本如下,是为了传递数据到b.aspx中作为查询条件function IMG1_onclick(e) { var Url= "../Common/b.aspx"; var Transforms =document.Form1.TxtSearchFile.value; var index; if(Transforms.length ==1) { for(index=0;index<1;index++) { if(Transforms.charCodeAt(index)>0x4E00||Transforms.charCodeAt(index)<0x9FA5) { } } } Url = Url+"?FileName="+Transforms+"&SearchIndex=1&SearchType="+document.Form1.Ddl_choicefile.value; e.target="Folders"; e.href =Url; }可是数据传递到b.aspx中 会出现如果传递的是两个中文字符或者英文字母及单词都没有问题用request.querystring可以获得,但是一旦输入一个中文字符,就会出现解析不了调试的时候会出现string s =request.querystring["filename"];结果为:s="?filename=&fileindex=1";问为什么会出现以上的结果 for(int i=0;;i++){ Console.write(i);//应该大写Console} c# sql如何写 C# 如何调用网络传真机自动传真 Beyondbit.Framework是什么框架? winform 无法显示界面 vs2008,怎么回到上一个编辑位置。 在WinForm中,ArrayList 怎么绑定到DataGrid??? 初始化的疑问????????????????? 能不能对用DataView.RowFilter()筛选条件后的记录进行操作?如删除.. 如何通过插件来调用客户端程序? 把DataGrid绑定到数万条记录的表会很慢吗? UDP协议通讯的一个问题. 求虚拟打印机实现思路
for(int i; i=0;;i++)
{
console.write(i);
}
题都错了
for(int i; i=0;;i++)
{
console.write(i);
}题怎么错了?无非是个死循环而已....
{
console.write(i);
}
这个题目也行...差点又马虎.
{
console.write(i);
}这样编译能通过!是这样的吧?
for(int i, i=0;;i++)
{
console.write(i);
}
{
Console.Write(i);
}无限循环
试题原题目
int i;
for(i=0;;i++)
{
}
我写成
for(int i=0;;i++)
{
console.write(i);
}
两种都行...
楼上的那样写不能编译.
{
console.write(i);
}通过不了。没试成功
{
console.write(i);
}
这个会出错,因为i没有初值for (int i = 0; ; i++)
{
Console.Write(i);
}
当超过int的长度会出错,int有多长我忘了-_#基础都跟压饭底了
{
Console.Write(i);
}这个更有意思。不过在C++中更好玩一点:for(int i; i=0; i++)
{
cout << i;
}
{
console.write(i);
}
for(int i; i=0;;i++)这条语句能行吗?for(int i; 这里要求是一个Bool的;;i++)
晕倒,有这个时间发这个贴,为啥不用C#写一个Demo试试看????
本人感觉现在招聘方出的题目水平越来越低下了。比如1!+2!+...+n!这样的题目也出来了,没有足够的时间我看人事部的(如果纯嵌套实现)也不能在1个小时内完成。可能是太自大了。
下面放我在笔试后的解决代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace _1__2____n_
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(24, 16);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "输入一个自然数";
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(136, 16);
this.label1.TabIndex = 1;
this.label1.Text = "结果在下面:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(176, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 24);
this.button1.TabIndex = 0;
this.button1.Text = "运行";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.AutoSize = false;
this.textBox2.Location = new System.Drawing.Point(8, 72);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(256, 40);
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
//
// Form1
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(280, 118);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
int i=int.Parse(this.textBox1.Text);
this.textBox2.Text=goon(i,i).ToString();
} private int goon(int n,int k)
{
if(0==k&&0==n)return 1;
else
{
if(0==k) return 0;
else if(1==k)
{
if(1==n)return 1;
else return n=n*goon(n-1,k);
}
else return goon(n,k-1)+goon(n-1,k-1)-goon(n-1,k-2);
}
}
}
}
for(int i=0;;i=i+1000000)
{
Console.WriteLine(i);
}
验证为死循环
{
console.write(i);
}
死循环,最后会溢出.
{
Console.Write(i);
}
不过肯定超过int的范围肯定会报错的
{
Console.Write(i);
}
这应该时个死循环
当int达到最大65536时抛出异常 我试了 就时不抛出异常
怎么回事
汇编出来都是jmp循环跳转
{
Console.Write("i");
}
int i;
for(i=0;;i++)
{
printf("%d\n",i);
}
从0~32767就转入-32767~0
我刚作过试验!
回去好好学学数学好吗?基本的数学公式你不知道?
要是出1+2---------+N的话估计你就会知道了
{
Console.write(i);
}
不会有溢出,省略第二条件,第二条件黑认为True;所以死循环。
不过还是觉得出题的人有点白痴变态。
还以为for里面可以使用三个冒号!
在a.spx文件中有一段脚本如下,是为了传递数据到b.aspx中作为查询条件
function IMG1_onclick(e)
{
var Url= "../Common/b.aspx";
var Transforms =document.Form1.TxtSearchFile.value;
var index;
if(Transforms.length ==1)
{
for(index=0;index<1;index++)
{
if(Transforms.charCodeAt(index)>0x4E00||Transforms.charCodeAt(index)<0x9FA5)
{
}
}
}
Url = Url+"?FileName="+Transforms+"&SearchIndex=1&SearchType="+document.Form1.Ddl_choicefile.value;
e.target="Folders";
e.href =Url; }
可是数据传递到b.aspx中 会出现
如果传递的是两个中文字符或者英文字母及单词都没有问题
用request.querystring可以获得,但是一旦输入一个中文字符,就会出现解析不了
调试的时候会出现string s =request.querystring["filename"];
结果为:s="?filename=&fileindex=1";
问为什么会出现以上的结果
{
Console.write(i);//应该大写Console
}