头歌java实训答案集
头歌MySQL数据库实训答案 有目录
专题一:C# 基础知识 C#变量 第1关 简单类型using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Introducing
{
class b1
{
static void Main(string[] args)
{
/********** Begin *********/
//定义变量:name和age
string name="Jackie";
int age=56;
//输出
Console.WriteLine("His name is "+name);
Console.WriteLine("his age is "+age);
/********** End *********/
}
}
}
第2关 命名规则
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B2b
{
class Program
{
static void Main(string[] args)
{
/********** Begin *********/
int fileSystem = 100;
string myname = "Jackie";
string string1 = "words";
int iLove= 521;
Console.WriteLine(fileSystem);
Console.WriteLine(myname);
Console.WriteLine(string1);
Console.WriteLine(iLove);
/********** End *********/
Console.WriteLine("You have successfully corrected this section of the code");
}
}
}
第3关 转义字符及Unicode值
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B3
{
class b3
{
static void Main(string[] args)
{
/********** Begin *********/
//请运用转义字符相关知识
//按照任务要求将一段文字完整打印出来
Console.Write("Ben:\"Listen to me, son\"\nPeter:\"Yeah, go ahead\"\nBen:\"You are a lot like your father, Peter\"\nBen:\"But your father believed that if you could do good things for other people, you had a moral obligation to do those things\"\nBen:\"Not choice. Responsibility\"\nPeter:\"That is nice. That’s great\"");
/********** End *********/
}
}
}
第4关 运算符的优先级
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B4
{
class Program
{
static void Main(string[] args)
{
/********** Begin *********/
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int f = (a + b) * c - d;
/********** End *********/
Console.WriteLine(f);
}
}
}
C#变量拓展
第1关 类型转换
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C1
{
class Program
{
static void Main(string[] args)
{
//Read a set of data
string a = Console.ReadLine();
string b = Console.ReadLine();
string c = Console.ReadLine();
int result = 0;
/********** Begin *********/
int a1=int.Parse(a);
int b1=int.Parse(b);
int c1=int.Parse(c);
result=a1*b1*c1;
/********** End *********/
Console.WriteLine(result);
}
}
}
第2关 复杂类型之枚举
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C1
{
class Program
{
/********** Begin *********/
enum Season :int{Summer=1,Autumn}
/********** End *********/
static void Main(string[] args)
{
Season mySeason = Season.Summer + 1;
Console.WriteLine("mySeason is " + mySeason);
}
}
}
第3关 复杂类型之结构
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C1
{
class Program
{
/********** Begin *********/
//define struct type
struct person{
public string city;
public string zipCode;
public int weight;
}
/********** End *********/
static void Main(string[] args)
{
/********** Begin *********/
//use struct type
person myFriend;
myFriend.city="Beijing";
myFriend.zipCode="343322";
myFriend.weight=45;
/********** End *********/
Console.WriteLine("Your city is " + myFriend.city + ", your zip code is " + myFriend.zipCode + ", your weight is " + myFriend.weight);
}
}
}
第4关 复杂类型之数组
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C1
{
class Program
{
static void Main(string[] args)
{
/********** Begin *********/
//Define an array of arrays: a
int [][] a={new int[]{1,2,3,},new int[]{4,1,6}};
/********** End *********/
//Initialize the array
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
a[i][j] = i * j;
}
}
/********** Begin *********/
//Print the second row of column 2 of array a
Console.WriteLine("数组a第二行第二列的值:"+a[1][1]);
/********** End *********/
}
}
}
C#初体验
第1关 第一个程序:Hello World
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A1
{
class Program
{
/********** Begin *********/
// 请补全符合规范的main()函数
static void Main(string[] args)
{
Console.WriteLine("Hello World, C#");
//请补全代码段
}
/********** End *********/
}
}
第2关 简单类型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A2
{
class Program
{
static void Main(string[] args)
{
/********** Begin *********/
//定义变量:name和age
string name="Jackie";
int age=56;
//输出
Console.WriteLine("His name is "+name);
Console.WriteLine("his age is "+age);
/********** End *********/
}
}
}
第3关 C#输入输出,模拟一段对话的过程
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A3
{
class Program
{
static void Main(string[] args)
{
/********** Begin *********/
Console.WriteLine("Listen to me, son");
Console.WriteLine("You are a lot like your father, Peter");
Console.WriteLine("But your father believed that if you could do good things for other people, you had a moral obligation to do those things");
Console.WriteLine("Not choice. Responsibility");
/********** End *********/
}
}
}
C#循环语句
第1关 while循环
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace F1
{
class Program
{
static void Main(string[] args)
{
int[] array = { 1, 2, 6, 9, 4, 7, 13, 12, 5, 3, 8, 10, 11 };
/********** Begin *********/
int temp = 0;
int i = 0;
while (i < array.Length-1) {
int j=0; //计数器j
while (j < array.Length - 1 - i) {
if (array[j] > array[j + 1]) {
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
j++;
}
i++;
}
/********** End *********/
int size = 0;
while (size < array.Length)
{
Console.WriteLine(array[size]);
size++;
}
}
}
}
第2关 do循环
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace F2
{
class Program
{
static void Main(string[] args)
{
/********** Begin *********/
int[] array = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 };
int temp = 0;
int i = 0;
do
{
int j = 0;
do
{
if (array[j] > array[j + 1])
{
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
j++;
} while (j < array.Length - 1 - i) ;
i++;
} while (i < array.Length - 1);
int size = 0;
while (size < array.Length)
{
Console.WriteLine(array[size]);
size++;
}
/********** End *********/
}
}
}
第3关 for循环
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace F3
{
class Program
{
static void Main(string[] args)
{
int[] array = { 1, 2, 6, 9, 4, 7, 13, 12, 5, 3, 8, 10, 11 };
int temp = 0;
/********** Begin *********/
for(int i=0; i < array.Length - 1; i++)
{
for (int j = 0; j < array.Length - 1 - i; j++)
{
if (array[j] > array[j + 1])
{
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
}
/********** End *********/
int size = 0;
while (size < array.Length)
{ //输出排序后的数组
Console.WriteLine(array[size]);
size++;
}
}
}
}
第4关 foreach循环
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace F3
{
class Program
{
static void Main(string[] args)
{
string[] nameList = { "Jackie", "Quentin", "Anna", "Charlize", "Eva", "Audrey", "Aoisola" };
/********** Begin *********/
Console.WriteLine("Now start naming");
foreach(string a in nameList){
Console.WriteLine(a);
}
/********** End *********/
Console.WriteLine("Great. Let's start");
}
}}
第5关 循环中断
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace F4
{
class Program
{
static void Main(string[] args)
{
/********** Begin *********/
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
if (i * j == 56) {
Console.WriteLine("we found 56");
return;
}
}
Console.Write("\n");
}
/********** End *********/
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)