为了账号安全,请及时绑定邮箱和手机立即绑定
课程 \ C#开发轻松入门

C#开发轻松入门

5-5 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
//声明整型数组,保存一组整数
int[] num = new int[] { 3,34,42,2,11,19,30,55,20};
//请完善代码,循环打印数组中的偶数
for(int i = 0; i < num.Length; i++ )
{
if(num[i]%2==0)
{
Console.Write(num[i]);
Console.Write(",");
}
}
}
}
}
2020-10-16 查看完整代码
5-2 C#访问数组元素
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
//声明“职位”数组,初始化为:"经理","项目主管","技术总监","财务主管"
string[] job = new string[4];
job[0]="经理";
job[1]="项目主管";
job[2]="技术总监";
job[3]="财务主管";
for (int i = 0; i < ; i++)
{
Console.WriteLine(job[i]);//打印职位
}
}
}
}
2020-10-16 查看完整代码
5-1 C#的声明数组和赋值
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int[] age = new int[4];//声明并初始化长度为4的整形数组
//为数组元素赋值
age[0] = 18;
age[1] = 20;
age[2] = 23;
age[3] = 17;
Console.WriteLine("四名同学的年龄是:{0}、{1}、{2}、{3}",
age[0],age[1],age[2],age[3]);
}
}
}
2020-10-16 查看完整代码
3-5 C#中嵌套的if结构
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
char sex='男';//性别
int age = 21;//年龄
if(sex == '女')//请填写条件
{
if (age >= 20)
{
Console.WriteLine("达到法定婚龄啦");
}
else
{
Console.WriteLine("没有达到哟");
}
}
else
{
if (age >= 22)
{
Console.WriteLine("达到法定婚龄!");
}
else
{
Console.WriteLine("没有达到!");
}
}
}
}
}
2020-10-16 查看完整代码
3-4 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double price = 4388;//手机的售价
double salary = 4978.67;//本月实发工资
//请在这里补充条件判断
if(price<salary)
{
Console.WriteLine("这月工资够买手机!");
}
else{
Console.WriteLine("这月工资不够买手机!");
}
}
}
}
2020-10-16 查看完整代码
3-3 C#中if...else条件结构
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int age = 17;//年龄
if (age>=18)//条件,bool类型
{//分支1
Console.WriteLine( "你是成年人");
}
else
{//分支2
Console.WriteLine("你是小盆友");
}
}
}
}
2020-10-16 查看完整代码
3-2 C#中判断和分支
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int score = 96;//分数
//判断
if(score > 95)
{//分支1
Console.WriteLine("奖励一辆自行车");
}
}
}
}
2020-10-16 查看完整代码
3-1 C#用流程图描述程序逻辑
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double x = 13.9, y = 24.4;
double sum = x + y;
double avg = sum / 2;
Console.WriteLine(avg);
}
}
}
2020-10-16 查看完整代码
2-22 C#的运算符优先级
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int x=1;
bool a = ++x * x > 3;
bool b = x == 2;//请赋值
Console.WriteLine(a==b);
}
}
}
2020-10-16 查看完整代码
2-21 C#的赋值运算符
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double x, y;
x = y = 2;//从右向左赋值,x、y的值都是2
x /= 0.5;
y -= 2;
Console.WriteLine(x-y);
}
}
}
2020-10-16 查看完整代码
2-19 C#的逻辑运算符(二)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int age = 4;//年龄
if (age < 6 || age > 60)
Console.WriteLine("请坐爱心座!");
else
Console.WriteLine("请坚持一下!");
}
}
}
2020-10-16 查看完整代码
2-18 C#的逻辑运算符(一)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(true||false);//输出True
Console.WriteLine(true&&false);//输出False
Console.WriteLine(!false);//输出True
}
}
}
2020-10-16 查看完整代码
2-17 C#的比较运算符
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double x = 3.5;
int y = 3;
Console.WriteLine((double)x>y);
}
}
}
2020-10-16 查看完整代码
2-15 C#的算术运算符(三)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int x = 5;
int y = 5;
int z = 5;
x++;
Console.Write(x);
Console.Write(++y);
Console.Write(++z);
}
}
}
2020-10-16 查看完整代码
2-14 C#的算术运算符(二)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int year = 2015;//年份
Console.WriteLine(2015%4);//求年份除以4的余数
}
}
}
2020-10-16 查看完整代码
2-11 C#标识符的命名规则
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int _num1 = 5;//第一个加数
int _num2 = 7;//第二个加数
int sum=_num1+_num2;//求和
Console.WriteLine("和是{0}",sum);//打印结果
}
}
}
2020-10-16 查看完整代码
2-10 C#的类型转换
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double d = 2.5;
int x = (int)d + 1;
Console.WriteLine(x);
}
}
}
2020-10-16 查看完整代码
2-9 C#的数据类型
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string name = "曹少钦";//姓名,string类型
char sex = '男';//性别,char类型
int age = 19;//年龄,int类型
double height = 1.72;//身高,double类型
Console.WriteLine("我叫{0},是{1}生,今年{2}岁,身高{3}米。",name,sex,age,height);
}
}
}
2020-10-16 查看完整代码
2-8 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string today;//今天的午饭
string tomorrow;//明天的午饭
today = "鱼香肉丝";
tomorrow = "小鸡炖蘑菇";
//请在这里补充代码,实现变量today和tomorrow的交换
string temp = today;
today = tomorrow;
tomorrow = temp;






//打印
Console.WriteLine("我今天吃{0},明天吃{1}。",today,tomorrow);
}
}
}
2020-10-16 查看完整代码
2-7 算法——交换
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string boy = "秀丽";//男孩名字
string girl = "伟强";//女孩名字
string temp;//中间变量
temp = boy;//把男孩的名字赋值给temp
boy = girl;//把女孩的名字赋值给男孩
girl = temp;//把temp中的名字赋值给女孩
Console.WriteLine("男孩叫"+boy+" 女孩叫"+girl);
}
}
}
2020-10-16 查看完整代码
首页上一页12下一页尾页
意见反馈 帮助中心 APP下载
官方微信