1偷厦、在控制臺輸入2個單詞,hello和world,然后組成一句話并輸出叉袍。
string str = Console.ReadLine();
string str1 = Console.ReadLine();
string str2 = str +" " + str1;
Console.WriteLine ("{0}",str2);
2、輸入班上所有同學的名字刽酱,輸入完成后輸出所有姓劉的學生的名字喳逛。
string names = "";
for (int i = 0; i < 5; i++) {
? ? ? ? ? ? ? ? ? ? string str = Console.ReadLine ();
if (str.StartsWith("劉")) {
? ? ? ? ? ? ? ? ? ? names +=( str+" ,");
? ? ? ? ? ?}
}
Console.WriteLine ("班上所有姓劉的人為:{0}",names);
3、輸入一個字符棵里,判斷它如果是小寫字母輸出其對應(yīng)大寫字母润文,如果是大寫字母輸出其對應(yīng)小寫字母姐呐,
如果是數(shù)字輸出其相反數(shù),如果是空格典蝌,輸出“space”曙砂,
如果不是上述情況,輸出“other”骏掀。(提示使用Console.Read()
int n = Console.Read(); ? ? ? ? ? ? ? ? ? ? ? //ACLL碼
if (n >= 65 && n <= 90) {? ? ? ? ? ? ? ? ? ? //大寫轉(zhuǎn)小寫
? ? ? ? ? ? ? ? Console.WriteLine ("{0}", (char)(n + 32)); ? ?//int值強轉(zhuǎn)字符
} else if (n >= 97 && n <= 122) { ? ? ??//小寫轉(zhuǎn)大寫
? ? ? ? ? ? ? ? Console.WriteLine ("{0}", (char)(n - 32));
} else if (n >= 48 && n <= 57) {
? ? ? ? ? ? ? ? Console.WriteLine ("{0}",-(n - 48));
} else if (n == 32) {
? ? ? ? ? ? ? ? Console.WriteLine ("Space");
} else {
? ? ? ? ? ? ? ? Console.WriteLine ("Other");
}
4鸠澈、已知abc + cba = 1333,其中a,b,c均為一位數(shù),編程求出滿足條件的a,b,c所有的組合截驮;
//987 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (int)(987/100) = 9 ? ? ??
//987? 987%100 = 87 ? ? ? ? (int)(87/10)=8
//987 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?987%10 = 7
for (int a = 1; a < 10; ++a) {
? ? ? ? for (int b = 0; b < 10; ++b) {
? ? ? ? ? ? ? ?for (int c = 1; c < 10; ++c) {
? ? ? ? ? ? ? ? ? ? ? ? if ((a*100+b*10+c)+(c*100+b*10+a) == 1333) {
? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine ("a={0},b={1},c={2}",a,b,c);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ?}
}