集合ArrayList案例
1.添加元素,读取
ArrayList n = new ArrayList();
n.Add();//集合中添加元素用Add,分别添加了1,2
n.Add(); foreach (int a in n)//用foreach循环语句读取
{
Console.WriteLine(a);
}
2.学生成绩输入,排序、求平均分
ArrayList cj = new ArrayList();
for (int i = ; i < ; i++)
{
Console.WriteLine("请输入第{0}同学的成绩", i + );
cj.Add(Convert.ToInt32(Console.ReadLine()));
}
int sum = ;
foreach (int a in cj)
{
sum = sum + a;
}
int avg = sum / cj.Count;
cj.Sort(); Console.WriteLine("平均分为:" + avg);
foreach (int a in cj)
{
Console.WriteLine(a);
}
集合ArrayList案例的更多相关文章
- 《java入门第一季》之ArrayList集合小案例
案例一:去除集合里面的重复元素 package cn.itcast_04; import java.util.ArrayList; /* * ArrayList去除集合中字符串的重复值(字符串的内容相 ...
- 【Java】集合综合案例 - 播放器管理
集合综合案例 文章目录 集合综合案例 需求分析 项目演示 详细设计 代码实现 歌曲类 播放器类 播放列表类 测试 参考资料 播放器管理 需求分析 项目演示 详细设计 代码实现 重新搞一波 复习巩固 简 ...
- Java ArrayList和Vector、LinkedList与ArrayList、数组(Array)和列表集合(ArrayList)的区别
ArrayList和Vector的区别ArrayList与Vector主要从二方面来说. 一.同步性: Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同步 ...
- 集合ArrayList
/*集合ArrayList * 例如: * 1.创建:ArrayList<Egg> myList = new ArrayList<Egg>(); * Egg类型的集合 ...
- 面向对象之集合ArrayList
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...
- 集合及特殊集合arrayList
1,运用集合 arrayList 首先复制Colections加 : 创建arrayList ar =new arrayList(); ArrayList具体提供的功能:属性 ...
- Java 集合 ArrayList和LinkedList的几种循环遍历方式及性能对比分析 [ 转载 ]
Java 集合 ArrayList和LinkedList的几种循环遍历方式及性能对比分析 @author Trinea 原文链接:http://www.trinea.cn/android/arrayl ...
- 数组Array和列表集合ArrayList、LinkedList和Vector的区别
一.ArrayList和Vector的区别 ArrayList与Vector主要从以下方面来说. 1.同步性: Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同 ...
- 第三章泛型集合ArrayList 和Hashtable
第三章泛型集集合 ArrayList 变量名 = new ArrayList(); //相当与一个容器 他的执行using 是 using System.Collections; 变量名.ADD( ...
随机推荐
- Highchart 改编风力风向图
基于highchart修改而成的风力风向图 1.替换highchart.js drawpoints方法,替换内容如下: drawPoints: function() { var a, b = this ...
- 个人收集资料整理-WinForm
[2016-03-23 20:29:56] 别人收集常用: http://www.cnblogs.com/babycool/p/3541192.html
- The error indicates that IIS is in 32 bit mode, while this application is a 64 b it application and thus not compatible.
I was trying to install a new WSS v3 Sharepoint on a 64 bit Windows 2003 server today but the instal ...
- Redhat Linux内核升级全记录(转)
http://www.sina.com.cn 2001/06/15 15:38 中国电脑教育报 李红 Redhat Linux因为比较容易上手,所以用户很多.它系统配置完善,预装了丰富的应 ...
- adb server is out of date. killing... ADB server didn't ACK * failed to star
The connection to adb is down, and a severe error has occured. [-- :: - HelloOPone] You must restart ...
- CCNA实验(8) -- PPP & HDLC
HDLC帧格式与以太帧格式有很大差别,HDLC帧没有源MAC和目的MAC地址.HDLC不能提供验证,缺少对链路保护.Cisco设备与Cisco设备连接,可用HDLC封装.Cisco设备与非Cisco设 ...
- Android设置Activity背景为透明style
方法一: 通过Theme.Translucent @android:style/Theme.Translucent @android:style/Theme.Translucent.NoTitleBa ...
- ##DAY4 事件的基本概念、触摸的基本概念、响应者链、手势
##DAY4 事件的基本概念.触摸的基本概念.响应者链.手势 #pragma mark ———————事件的基本概念 ——————————— 事件的基本概念: 1)事件是当用户的手指触击屏幕及在屏幕 ...
- Node.js、Ionic、Cordova、AngualrJS安装
1.安装node.js: 从node.js官网下载node.js安装包,node.js下载地址:https://nodejs.org/en/download/,选择对应系统的安装下载后进行安装.(注: ...
- jQuery插件-jgcharts实现Javascript制作Google Charts
from:http://www.zz68.net/program/Ajax/2010/0415/1992.html jgcharts是一个基于jQuery的非常经典的Google Charts图表制作 ...