计算机与信息工程系课程实验报告
姓 名 | 翟园园 | 学 号 | 2014134031 | 班 级 | 3D仿真设计 |
课程名称 | 面向对象程序设计 | 实验类型 | 验证 | 实验地点 | M406 |
指导教师 | 魏青 | 实验日期 | 2015.03.20 | 实验成绩 |
|
实验名称 | 验证数组的声明、初始化及复制操作 | ||||
一、 实验目的及要求 熟悉数组的声明、初始化及复制操作 | |||||
三、实验步骤 (一)数组变量的声明 int a[];或int[] a; (二)为数组分配存储空间:new
int[] a a=new int[5]; }int[] a=new int[5]; (三)初始化数组 1. int[] a=new int[5]; a[0]=1,a[1]=2,a[2]=3 `````````; 2. int[] a=new int[]={1,2,3,4,5}; 3. int[] a={1,2,3,4.5};
(四)数组元素引用 1..import java.util.Scanner; public class ArrayDemo { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int[] score=new int[5]; For(int i=0;i<5;i++) { System.out.printf(“请输入第%d/5个整数:”,i+1); Score[i]=sc.nextInt(); } sc.close(); System.out.print(“你输入的整数是:”); for (int i=0;i<score.length;i++) { System.out.print(score[i]+”,”); } } } 2.System类提供的方法——arraycopy public class ArrayCopy { public static void main(String[] args) { Int myArray[]={1,2,3,4,5,6,}; Int hold [] ={10,9,8,7,6,5,4,3,2,1}; System.arraycopy(myArray,0,hold,0,myArray.length); } } 3.class Happy{ public static void main(String[] args) { int index=1; int a[]=new int[3]; int bas=a[index]; int baz=bas+index; System.out.println(a[baz]); }
| |||||
四、实验结果 1. 345 345 2. 1234564321 3. 0 | |||||
五、结果分析与实验体会 1.掌握java与c语言的区别。 2.实验过程掌握的不熟,自己无法独立编写完整正确的程序。应经常自己上级练习。 3.注意细节。如字母的大小写,分号的有无。 |
注:1、实验类型分为:演示、验证、综合、设计研究或其他。
2、附录:可附加源程序代码清单等。
六、附录(源程序代码清单等)