收藏 分享(赏)

实验八 数组.doc

上传人:fmgc7290 文档编号:9139174 上传时间:2019-07-25 格式:DOC 页数:5 大小:53.50KB
下载 相关 举报
实验八  数组.doc_第1页
第1页 / 共5页
实验八  数组.doc_第2页
第2页 / 共5页
实验八  数组.doc_第3页
第3页 / 共5页
实验八  数组.doc_第4页
第4页 / 共5页
实验八  数组.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、实验八 数组【开发语言及实现平台或实验环境】Windows2000 或 XP,JDK1.6 与 Eclipse 【实验目的】1. 掌握一维、二维和多维数组的定义、初始化和使用方法【实验要求】1. 掌握数 组 的 定 义 与 引 用 。【实验内容】1.一维数组:1)申明:int anIntArray; / 声明一个数组2)分配空间要为上面的数组变量 anIntArray 分配一个长度为 8 的整型数组:anIntArray=new int8;3)初始化及引用初始化数组,就是为数组的各个元素赋初值。如:int data1 = 1,2,3,4,5, 6,7,8,9,10 ;数组引用 数组名位置索引4

2、)数组遍历for(int i = 0; imax)max=mij;row=i;column=j;System.out.println(“max=“+max+“ locate at row=“+row+“ column=“+column); 该程序输出结果为:max=400 locate at row=1 column=0【完成实验项目】1. 设给定一组整型数组,求它们的平均值及最大值2. 使用动态建立二维数组的方式输出 8行杨辉三角形3. 用选择法对8,6,12,5,14,7,21,2,9,3十个数按从小到大进行排序,然后输出class Pinpublic static void main(S

3、tring args) int a=1,5,6,41,85,46,23,77;int max = 0;int len=0;len=a.length;int sum=0;for(int i=0;imax)max=ai;System.out.println(“最大值为:“ +max);3public class pai public static void main(String args) int a=8,6,12,5,14,7,21,2,9,3;for(int i=0;iaj)t=ai;ai=aj;aj=t;System.out.print(“排序后数组为:“ );for(int i=0;ia

4、.length;i+)System.out.print(“a“+i+“=“+ai+“ “);2public class yaanghuipublic static void main(String args)int i;int a=new int8;for(i=0;i8;i+)ai=new inti+1;ai0=1;aii=1;for(i=2;i8;i+)for(int j=1;ji;j+)aij=ai-1j-1+ai-1j;for(i=0;i8;i+)for(int j=0;j8-i;j+)System.out.print(“ “);for(int j=0;j=i;j+)System.out.print(aij+“ “);System.out.println();

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报