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

C#开发轻松入门

6-8 最终项目
using System;
using System.Collections.Generic;
using System.Text;

namespace projAboveAvg
{
class Program
{
static void Main(string[] args)
{
string[] name = { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };

int[] score = { 90, 65, 88, 70, 46, 81, 100, 68 };

int index = 0;

int sum = 0;

foreach (int x in score)

{

sum += x;

}

int avg = sum / (score.Length);

Console.WriteLine("平均分是{0},高于平均分的有:", avg);

string names = "";

for (int x = 0; x < score.Length;x++)

{

if (score[x] > avg)

{

names += name[x]+" ";

}

}

Console.Write(names);
}
}
}
2019-02-14 查看完整代码
6-1 练习题目
using System;
using System.Collections.Generic;
using System.Text;

namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
string[] names = new string[] {"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣",};
int[] fenshu = new int[] {89,90,98,56,60,91,93,85};
int max = 0;
for(int a = 0;a<fenshu.Length-1;a++)
{
if(fenshu[a]>fenshu[max])
{
max = a;
}
}
Console.Write("分数最高的是{0},分数是{1}",names[max],fenshu[max]);
// string[] name = {"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何坤","关欣"};

// int[] score = {89,90,98,56,60,91,93,85};

// int i = 0;

// for(int j =1;j<name.Length;j++)

// {

// if(score[j]>score[i])

// i=j;

// }

// Console.Write("分数最高的是{0},分数是{1}",name[i],score[i]);
}
}
}
2019-02-11 查看完整代码
5-9 C#的二维数组的声明和访问
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
char[,] ch = { {'我','是','软'},{'件','工','程'},{'师','啦','!'}};
Console.WriteLine("{0}{1}{2}",ch[1,1],ch[1,2],ch[2,0]);
}
}
}
2019-02-11 查看完整代码
5-8 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
//声明整型数组,保存一组整数
int[] num = new int[] { 3,34,43,2,11,19,30,55,20};
bool av = false;
for(int a = 0;a<num.Length;a++)
{
if(num[a]%7==0)
{
av = true;
break;
}
}
if(av)
{
Console.WriteLine("有7的整倍数");
}
else
{
Console.WriteLine("没有7的整倍数");
}
}
}
}
2019-02-11 查看完整代码
5-7 C#的foreach关键字
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string[] t =new string[]{"C","Sh","a","rp"};
//遍历字符串数组t
foreach(string x in t)
{
Console.Write(x);
}
}
}
}
2019-02-11 查看完整代码
5-6 算法——查找(二)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int[] score = { 85,76,98,100,62,60};//分数
bool hasNopass = false;//记录是否有不及格的,默认没有
for (int i = 0; i < score.Length; i++)
{
if (score[i] < 60)//如果有不及格的
{
hasNopass = true;//记录有不及格的
break;
}
}
if (hasNopass)
Console.WriteLine("有人不及格");
else
Console.WriteLine("都及格啦!");
}
}
}
2019-02-11 查看完整代码
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 a = 0;a<num.Length;a++)
{
if (num[a]%2==0)
{
Console.Write(num[a] +",");
}
}
}
}
}
2019-02-11 查看完整代码
5-4 算法——查找(一)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int[] score = new int[] {89,39,100,51,94,65,70 };//分数
Console.Write("不及格的有:");
for (int i = 0; i < score.Length ; i++)
{
if( score[i]<60 )//筛选条件
Console.Write(score[i]+",");
}
}
}
}
2019-02-11 查看完整代码
5-3 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string[] names = new string[] {"关羽","张飞","赵云","马超","黄忠"};//请在这里完善代码
for (int a = 0;a<names.Length;a++)
{
Console.Write(names[a]+",");
}
}
}
}
2019-02-11 查看完整代码
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[] {"经理","项目主管","技术总监","财务主管"};
for (int i = 0; i <job.Length ; i++)
{
Console.Write(job[i]);//打印职位
}
}
}
}
2019-02-11 查看完整代码
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]);
}
}
}
2019-02-11 查看完整代码
4-10 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
for (int x = 1;x<8;x++)
{
for (int y = 1;y<8;y++)
{
if (x==y || x+y==8)
{
Console.Write("O");
}
else
{
Console.Write(".");
}
}
}
Console.WriteLine("");
}
}
}
2019-02-11 查看完整代码
4-9 C#循环结构之嵌套循环
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= y; x++)
{
Console.Write(x);
}
Console.WriteLine();//换行
}
}
}
}
2019-02-11 查看完整代码
4-8 C#循环结构之break
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
for(int x=1;x<=5;x++)
{
if(x%2==0)
continue;//添加关键字break或continue
Console.Write(x);
}
}
}
}
2019-02-11 查看完整代码
4-7 C#循环结构之continue
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
for (int x = 1; x < 10; x++)
{
if (x==3 || x==8)
continue;//请添加代码,过滤3和8
Console.Write(x);
}
}
}
}
2019-02-11 查看完整代码
4-6 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
for (int x =0;x<6;x++)//请填写for循环结构
{
Console.WriteLine("Yeah!");
}
}
}
}
2019-02-11 查看完整代码
4-5 C#中do…while循环
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int x = 2;
do
{
x++;
Console.Write(x+" ");
}
while(x>2&&x<=4);
}
}
}
2019-02-11 查看完整代码
4-4 C#中for循环
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
for (int x =1;x<=12 ;x++ )//请填写代码
{
Console.WriteLine(x+" ");
}
}
}
}
2019-02-11 查看完整代码
4-3 C#算法——求和
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int x = 1;
int sum = 0;//和,初始化为0
while (x <= 30)//循环条件
{
if (x%2==1)//筛选条件
sum += x;
x++;
}
Console.Write("1-30奇数的和:"+sum);
}
}
}
2019-02-11 查看完整代码
4-2 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int x;//循环计数变量
x = 5;//行① 请填写计数变量的初始化语句


while (x>0)//行② 请填写循环条件
{
Console.Write("加油!");
x--;//行③ 请填写计数变量的自加语句

}
}
}
}
2019-02-11 查看完整代码
首页上一页123下一页尾页
意见反馈 帮助中心 APP下载
官方微信