1 i和j的值为多少
string s = "abcedfg 中国人"; int i = s.Length; int j = Encoding.Default.GetBytes(s).Length;
答案:i=11,j=14
2 实例化ClassB后输出结果
class ClassA { public ClassA() { Print(); } public virtual void Print() { } } class ClassB : ClassA { int a = 1; int b; public ClassB() { b = -1; Print(); } public override void Print() { Console.WriteLine("a="+a+" b="+b); } }
结果:a=1,b=0 a=1,b=-1
3 sql删除除主键外的重复数据
delete from StuInfo where ID not in(select MIN(id) from StuInfo group by Name,Dept,StuNo,Sex)
用Max或Min函数都行
4
找出所有科目的成绩都大于80的学生姓名。
思路1:所有大于80分就是名字不在小于80分的学生里面的学生,主要是用到了一个逆向思维
select distinct Name from Student where Name not in(select Name from Student where Score<80)
思路2:所有大于80分即该学生的最小成绩也大于80.
select name,MIN(Score) from Student group by Name having MIN(Score)>80
思路3:所有大于80分则要求该学生大于80分的科目要有3个(即科目数)。
select Name,COUNT(*) from Student where Score>80 group by Name having COUNT(*)=3
5.将1-100插入到一个长度为100的数组中
private static void Print() { Random rand = new Random(); int[] nums=new int[100]; int newNum; for (int i = 0; i < nums.Length; i++) { do { newNum = rand.Next(101); } while (nums.Contains(newNum)); nums[i] = newNum; } foreach (int i in nums) { Console.Write(i + " "); } }
6 求数列:1、1、2、3、5、8、13、21...的第N个数是多少
/// <summary> /// 斐波那契数列 /// </summary> /// <param name="i"></param> /// <returns></returns> private static int Fibonacci(int i) { if (i <=2) { return 1; } else { return Fibonacci(i - 1) + Fibonacci(i - 2); } }
7 统计某个字符串在文本中出现的次数。
/// <summary> /// 统计某个字符串在文本中的总数 /// </summary> /// <param name="text">要统计的文本</param> /// <param name="find">要统计的字符串</param> private static int Count(string text,string find) { int count = 0; int position = 0; int index = 0; do { index = text.IndexOf(find, position); if (index > 0) { position = index + 1; count++; } } while (index>0); return count; }
8 求数列: 1-2+3-4+5...+49-50的和
/// <summary> /// 直接用公式 /// </summary> /// <param name="i"></param> /// <returns></returns> private static int NumSum(int i) { if (i % 2 == 0) return (-1) * i / 2; else return (-1) * i / 2 + i; } /// <summary> /// 用递归 /// </summary> /// <param name="n"></param> /// <returns></returns> private static int NumSum2(int n) { if (n <= 0) { return 0; } else { return n % 2 == 0 ? NumSum2(n - 1) - n : NumSum2(n - 1) + n; } }