博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
二维数组,多维数组
阅读量:6121 次
发布时间:2019-06-21

本文共 4048 字,大约阅读时间需要 13 分钟。

二维数组,多维数组

//定义二维数组
 int[,] a=new int [3,2]     //3表示有三个一维数组,2表示每一个一位数组中有两个元素

int[,] a=new int [3,4]{            {1,2,3,4},            {5,6,7,8},            {9,8,7,6}            };            //打印出来            for (int i = 0; i < 3;i++ )            {                for(int j=0;j<4;j++)                {                    Console.Write(a[i,j]+"\t");                }                Console.WriteLine();            }

  

//输入班级人数,输入每人的语数英成绩再打印出来,求语文两个最高分,数学两个最低分,英语平均分 

1 Console.Write("输入班级人数:"); 2             int n = int.Parse(Console.ReadLine()); 3             double[,] a = new double[n, 3]; 4             for (int i = 0; i < n; i++) 5             { 6                 Console.Write("输入第{0}个人的语文成绩:", i + 1); 7                 a[i, 0] = double.Parse(Console.ReadLine()); 8                 Console.Write("输入第{0}个人的数学成绩:", i + 1); 9                 a[i, 1] = double.Parse(Console.ReadLine());10                 Console.Write("输入第{0}个人的英语成绩:", i + 1);11                 a[i, 2] = double.Parse(Console.ReadLine());12             }13             Console.WriteLine("输入完毕!");14             for (int i = 0; i < n; i++)15             {16                 for (int j = 0; j < 3; j++)17                 {18                     Console.Write(a[i, j] + "\t");19                 }20                 Console.WriteLine();21             }22             double sum = 0;23             for (int i = 0; i < n - 1; i++)24             {25                 for (int j = i + 1; j < n; j++)26                 {27                     if (a[i, 0] < a[j, 0])28                     {29                         double t = a[i, 0];30                         a[i, 0] = a[j, 0];31                         a[j, 0] = t;32                     }33                     if (a[i, 1] > a[j, 1])34                     {35                         double t = a[i, 1];36                         a[i, 1] = a[j, 1];37                         a[j, 1] = t;38                     }39                 }40                 sum += a[i, 2];41             }42             Console.WriteLine("语文两个最高分为{0},{1};数学两个最低分为{2},{3};英语平均分为{4}", a[0, 0], a[0, 1], a[1, 0], a[1, 1], sum / n);
View Code

 

//打印“马”这个字

1 string[,] a = new string[,]{ 2             {
" ","■","■","■","■"," ",""}, 3 {
" "," ","■"," ","■","",""}, 4 {
" "," ","■"," ","■","",""}, 5 {
" "," ","■","■","■","■","■"}, 6 {
" "," "," "," "," "," ","■"}, 7 {
"■","■","■","■","■","■","■"}, 8 {
" "," "," "," "," "," ","■"}, 9 {
" "," "," "," "," ","■","■"},10 };11 for (int i = 0; i < 8; i++)12 {13 for (int j = 0; j < 7; j++)14 {15 Console.Write(a[i, j]);16 }17 Console.WriteLine();18 }
View Code

 

//一维数组是一条线,二维数组是一个面(表格)

//三维数组是一个立体(教学楼)
//int[,,]a=new int[,,];

//split() 以***进行分割

//分割出来的内容放置在string类型中,不需要给数组定义长度

Console.Write("请输入姓名,年龄,工作单位:");            string s = Console.ReadLine();            string[] a = s.Split(',');            foreach (string aa in a)            {                Console.WriteLine(aa);            }

  

 //春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知道多少。替换文字

 

1 string a = "春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知道多少。";2             a = a.Replace("处", "这儿");3             Console.WriteLine(a);
方法一:

 

1 string[,] a = new string[4, 6] 2             { 3                 {
"春","眠","不","觉","晓",","}, 4 {
"处","处","闻","啼","鸟","。"}, 5 {
"夜","来","风","雨","声",","}, 6 {
"花","落","知","多","少","。"} 7 }; 8 for (int i = 0; i < 4; i++) 9 {10 for (int j = 0; j < 6; j++)11 {12 if (a[i, j] == "处")13 {14 a[i, j] = "这儿";15 }16 Console.Write(a[i, j]);17 }18 Console.WriteLine();19 }
方法二:
 

 

 

转载于:https://www.cnblogs.com/maxin991025-/p/5964285.html

你可能感兴趣的文章
好记性不如烂笔杆-android学习笔记<十六> switcher和gallery
查看>>
JAVA GC
查看>>
codeforce 599B Spongebob and Joke
查看>>
3springboot:springboot配置文件(外部配置加载顺序、自动配置原理,@Conditional)
查看>>
9、Dubbo-配置(4)
查看>>
前端第七天
查看>>
BZOJ 2190[SDOI2008]仪仗队
查看>>
图解SSH原理及两种登录方法
查看>>
[转载] 七龙珠第一部——第058话 魔境圣地
查看>>
【总结整理】JQuery基础学习---样式篇
查看>>
查询个人站点的文章、分类和标签查询
查看>>
基础知识:数字、字符串、列表 的类型及内置方法
查看>>
JSP的隐式对象
查看>>
P127、面试题20:顺时针打印矩阵
查看>>
JS图片跟着鼠标跑效果
查看>>
[SCOI2005][BZOJ 1084]最大子矩阵
查看>>
学习笔记之Data Visualization
查看>>
Leetcode 3. Longest Substring Without Repeating Characters
查看>>
【FJOI2015】金币换位问题
查看>>
数学之美系列二十 -- 自然语言处理的教父 马库斯
查看>>