标签:
var 声明局部变量
//程序员笑话 : http://news.mydrivers.com/1/407/407317.htm
然后课堂练习(我一个蹭课的写什么课堂练习啊。。。)
1.字符提取,整数整除练习
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BitAdd { class Program { static void Main(string[] args) { String s; s = Console.ReadLine(); Method1(s); Method2(s); } private static int Method2(String s) { int sum = 0, i = 0; int t = int.Parse(s); int []b = new int[100]; Console.Write("实现思路2:每一位的值为:"); while (t > 0) { b[i++] = t % 10; sum += t % 10; t /= 10; } for (int r = i- 1; r >= 0; r--) Console.Write(b[r] + "、"); Console.WriteLine(" 这些位之和为" + sum); return sum; } private static int Method1(String s) { int sum = 0; Console.Write("实现思路1:每一位的值为:"); for (int i = 0; i < s.Length; i++) { Console.Write((Convert.ToInt32(s[i]) - 48) + "、"); sum += Convert.ToInt32(s[i] - 48); } Console.WriteLine(" 这些位之和为" + sum); return sum; } } }
2. 5个整数的正序与倒序
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Array { class Program { static void Main(string[] args) { int[] n = new int[5]; string[] temp = new string[5]; string s = Console.ReadLine() ; temp = s.Split(‘,‘); for (int i = 0; i < 5; i++) n[i] = int.Parse(temp[i]); for(int i = 0; i < 5; i++) for(int r = 0; r < i; r++) if (n[i] > n[r]) { int tt = n[i]; n[i] = n[r]; n[r] = tt; } Console.Write("正序:"); for (int i = 4; i >= 0; i--) Console.Write(n[i] + " "); Console.WriteLine(); Console.Write("倒序:"); for (int i = 0; i < 5; i++) Console.Write(n[i] + " "); Console.WriteLine(); } } }
3.简易计算器(Windows) ..待补充
标签:
原文地址:http://www.cnblogs.com/QQ-1615160629/p/5867976.html