作業(yè)1
?/**
* ?作業(yè)1:要求用戶輸入兩個數(shù)a冒版、b,如果a被b整除或者a加b大于100逞姿,則輸出a的值辞嗡,否則輸出b的值
* */
代碼
Console.WriteLine("請輸入第一個數(shù)");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("請輸入第二個數(shù)");
int b = Convert.ToInt32(Console.ReadLine());
if (b % a == 0 || a + b > 100)
{Console.WriteLine("{0}", a);}
else { Console.WriteLine("{0}", b); }
Console.ReadKey();
效果
作業(yè)2
/**
* 提示用戶輸入密碼捆等,如果密碼是“88888”則提示正確,否則提示錯誤,程序結(jié)束续室。
* */
代碼
Console.WriteLine("請輸入密碼");
string mima = Console.ReadLine();
if (mima == "88888")
{ Console.WriteLine("密碼正確"); }
else
{ Console.WriteLine("密碼錯誤栋烤,程序結(jié)束"); }
Console.ReadKey();
作業(yè)3
/**
* 提示用戶輸入用戶名,然后再提示輸入密碼猎贴,
* 如果用戶名是“admin”并且密碼是“88888”班缎,則提示正確,
* 否則她渴,如果用戶名不是admin還提示用戶用戶名不存在,如果用戶名是admin則提示密碼錯誤
* */
代碼
Console.WriteLine("請您的用戶名");
string yonghuming = Console.ReadLine();
Console.WriteLine("請您的密碼");
string mima = Console.ReadLine();
if (yonghuming == "admin")
{
if (mima == "88888")
{ Console.WriteLine("正確"); }
else { Console.WriteLine("密碼錯誤"); }
}
else
{ Console.WriteLine("此用戶名不存在"); }
Console.ReadKey();
作業(yè)4
/**
? ? ? ? ? ? *提示用戶輸入年齡达址,
? ? ? ? ? ? *如果大于等于18,則告知用戶可以查看趁耗,
? ? ? ? ? ? *如果小于10歲沉唠,則告知不允許查看,
? ? ? ? ? ? *如果大于等于10歲并且小于18苛败,則提示用戶是否繼續(xù)查看(yes满葛、no),
? ? ? ? ? ? *如果輸入的是yes則提示用戶請查看罢屈,否則提示"退出,你放棄查看"嘀韧。
? ? ? ? ? ? * */
代碼
? ? ? ? ? ? Console.WriteLine("請您的年齡");
? ? ? ? ? ? int nianlian = Convert.ToInt32(Console.ReadLine());
? ? ? ? ? ? if (nianlian > 18)
? ? ? ? ? ? { Console.WriteLine("可以查看"); }
? ? ? ? ? ? else if (nianlian < 10)
? ? ? ? ? ? { Console.WriteLine("不允許查看"); }
? ? ? ? ? ? else { Console.WriteLine("請輸入是否繼續(xù)查看(yes、no)"); }
? ? ? ? ? ? string xuanzhe = Console.ReadLine();
? ? ? ? ? ? if (xuanzhe == "yes") { Console.WriteLine("請查看");}
? ? ? ? ? ? else { Console.WriteLine("退出,你放棄查看");}
? ? ? ? ? ? Console.ReadKey();