55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
|
|
using System;
|
||
|
|
namespace Lesson10
|
||
|
|
{
|
||
|
|
class program
|
||
|
|
{
|
||
|
|
static void Main(string[] args)
|
||
|
|
{
|
||
|
|
#region 年龄
|
||
|
|
int myAge = 18;
|
||
|
|
myAge += 10;
|
||
|
|
Console.WriteLine("十年后我的年龄是:" + myAge);
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
|
||
|
|
#region 圆的面积
|
||
|
|
const float PI = 3.1415926f;
|
||
|
|
int radius = 5;
|
||
|
|
float area = PI * radius * radius;
|
||
|
|
float circumference = 2f * PI * radius;
|
||
|
|
Console.WriteLine("半径为" + radius + "的圆的面积是:" + area + "周长是:" + circumference);
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region 计算成绩
|
||
|
|
int score1 = 80;
|
||
|
|
int score2 = 90;
|
||
|
|
int score3 = 92;
|
||
|
|
int totalScore = score1 + score2 + score3;
|
||
|
|
float avgScore = totalScore / 3.0f;
|
||
|
|
Console.WriteLine("你的总成绩为:" + totalScore);
|
||
|
|
Console.WriteLine("你的平均分为:" + avgScore);
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region 交换变量值
|
||
|
|
int a = 99;
|
||
|
|
int b = 87;
|
||
|
|
int temp;
|
||
|
|
temp = a;
|
||
|
|
a = b;
|
||
|
|
b = temp;
|
||
|
|
Console.WriteLine($"交换后A的值为:{a}B的值为:{b}");
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region 时间转换
|
||
|
|
int second = 987652;
|
||
|
|
int hour, minute, day;
|
||
|
|
day = second / 86400; // 1天 = 86400秒
|
||
|
|
hour = (second - (day * 86400)) / 3600; // 1小时 = 3600秒
|
||
|
|
minute = (second - (day * 86400 + hour * 3600)) / 60; // 1分钟 = 60秒
|
||
|
|
second = second - (day * 86400 + hour * 3600 + minute * 60);
|
||
|
|
Console.WriteLine($"转换后的时间为{day}天{hour}小时{minute}分钟{second}秒");
|
||
|
|
#endregion
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|