…
作業(yè)1
…
要求用戶輸入兩個(gè)數(shù)a、b,如果a被b整除或者a加b大于100,則輸出a的值,否則輸出b的值
…
代碼
…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請(qǐng)輸入a的值");
string str_a = Console.ReadLine();
int a = Convert.ToInt32(str_a);
Console.WriteLine("請(qǐng)輸入b的值");
string str_b = Console.ReadLine();
int b= Convert.ToInt32(str_b);
bool c = a % b == 0 || a + b > 100;
if (c)
Console.WriteLine(a);
else
Console.WriteLine(b);
Console.ReadKey();
}
}
}
…
效果
…

…
作業(yè)2
…
提示用戶輸入密碼,如果密碼是“88888”則提示正確,否則提示錯(cuò)誤,程序結(jié)束。
…
代碼
…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請(qǐng)輸入密碼");
string str_a = Console.ReadLine();
int a = Convert.ToInt32(str_a);
bool b = a==88888;
if (b)
Console.WriteLine("正確");
else
Console.WriteLine("錯(cuò)誤");
Console.WriteLine("程序結(jié)束");
Console.ReadKey();
}
}
}
…
效果
…

…
作業(yè)3
…
提示用戶輸入用戶名,然后再提示輸入密碼,如果用戶名是“admin”并且密碼是“88888”,則提示正確,否則,如果用戶名不是admin還提示用戶用戶名不存在,如果用戶名是admin則提示密碼錯(cuò)誤.
…
代碼
…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請(qǐng)輸入用戶名");
string str_username = Console.ReadLine();
string username = str_username;
Console.WriteLine("請(qǐng)輸入密碼");
string str_password = Console.ReadLine();
string password = str_password;
bool b =username=="admin"&&password=="88888";
if (b)
Console.WriteLine("正確");
else if (username!="admin")
Console.WriteLine("用戶名不存在");
else
Console.WriteLine("密碼錯(cuò)誤");
Console.WriteLine("程序結(jié)束");
Console.ReadKey();
}
}
}
…
效果
…

…
作業(yè)4
…
提示用戶輸入年齡,如果大于等于18,則告知用戶可以查看,如果小于10歲,則告知不允許查看,如果大于等于10歲并且小于18,則提示用戶是否繼續(xù)查看(yes、no),如果輸入的是yes則提示用戶請(qǐng)查看,否則提示"退出,你放棄查看"。
…
代碼
…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請(qǐng)輸入年齡");
string str_age = Console.ReadLine();
int age = Convert.ToInt32(str_age);
bool b = age >= 10 && age < 18;
if (b)
Console.WriteLine("是否繼續(xù)查看");
string str_choose = Console.ReadLine();
string choose = str_choose;
bool c = choose == "yes";
if (c)
Console.WriteLine("請(qǐng)查看");
else if (choose == "no")
Console.WriteLine("退出,你放棄查看");
if (age < 10)
Console.WriteLine("不允許查看");
if(age>=18)
Console.WriteLine("可以查看");
Console.ReadKey();
}
}
}
…
效果
…




…