C#判断语句编程求助~~~
用程序实现如下功能A、提示输入用户年龄。
B、如果年龄>18 则可查看,<10不能查看
C、如果年龄>=10,提示用户是否继续查看,根据输入1继续查看,0不让查看。
(提示:用控制台应用程序实现;使用条件判断语句的嵌套来实现判断)
用程序实现如下功能A、提示输入用户年龄。
B、如果年龄>18 则可查看,<10不能查看
C、如果年龄>=10,提示用户是否继续查看,根据输入1继续查看,0不让查看。
(提示:用控制台应用程序实现;使用条件判断语句的嵌套来实现判断)
答案:static void Main(string[] args)
{
int age = 0;
Console.Write("请输入年龄:");
while (!int.TryParse(Console.ReadLine(), out age))
{
Console.Write("请输入年龄(数字):");
}
if (age > 18)
{
Console.Write("查看结果如下");
}
else if (age >=10)
{
Console.Write("是否继续查看,1-继续查看,0-不继续:");
int temp = 0;
while (!int.TryParse(Console.ReadLine(), out temp) || (temp!=0 && temp!=1))
{
Console.Write("请输入1或者0:");
}
if (temp == 1)
{
Console.Write("查看结果如下");
}
else if(temp == 0)
{
Console.Write("不能查看");
}
}
else if (age < 10)
{
Console.Write("不能查看");
}
int i = Console.Read();
}using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{Console.WriteLine("请输入年龄:");
int age = int.Parse(Console.ReadLine());
if (age > 18)
{
Console.WriteLine("你可以查看信息。");
}
else if (age <= 18)
{
if (age <= 10)
Console.WriteLine("你不能查看信息。");
else
{
Console.WriteLine("你确定查看信息吗?(Y/N)");
if (Console.ReadLine().ToLower().Trim() == "y")
{
Console.WriteLine("你查看了信息。");
}
else
{
Console.WriteLine("你没查看信息。");
}
}
}
}
}
}
上一个:C# 窗体编程 入门好书推荐
下一个:寻求C# 网络编程的书