java实训第六次课后实训——数组
来源:互联网 发布:网络硬盘录像机怎么用 编辑:程序博客网 时间:2024/06/16 09:03
数组
1.
100
一维数组 a[0]=100 1001
int[] a; a+0*4=1001 1002
int[] a={1,2,3,4}; 1003
int[] a=new int[5]; 1004
int[] a=new int[]{5,6,7}; 1005
a[1] a+1*4=1005
a[2] a+2*4=1009
2.为什么数组下标从0开始:数组变量本身拿着内存地址的一第片地址。
3.i.length 数组长度
4. for(h:i1){ //打印数组
System.out.print(h);
}
= for(int u=0;u<i1.length;u++){
Int h=i1[u];
System.out.println(h);
}
5.冒泡排序
int[] i={10,50,66,7,12,78};
for(int a=0;a<i.length-1;a++){
for(inty=i.length-1;y>a;y--){
If(i[y]<i[y-1]) {
int h=i[y];
i[y]=i[y-1];
i[y-1]=h;
}
输出:
7 10 12 50 66 78
}
}
for(int j:i){
System.out.println(j+” ”);
}
6.二维数组:int[][] a= new int[3][3];
//int [][]a=new int [][]{{10,20},{30,40}};
int [][]a=new int[2][];
a[0]=new int[]{10,50,60};
a[1]=new int[]{1,45,2,52,22,21};
/for(int[] list:a){ //行
for(int u:list){ //列
System.out.print(u+” ”);
}
System.out.println(“ ”);
}/
for(int i=0;i<a.length;i++){
for(int u=0;u<a[i].length;u++){
System.out.print(a[i][u]+” ”);
}
System.out.println(“ ”);
100
}
7.eg.int[][].i=newint[3][];
i[0].length i[0][2]=100
i[0]=new int[3];
i.length i[1]=new int[2];
i[2]=new int[1];
i[1].length
8.①对象数组
class Dog{
String name;
}
① Dog[] ds=new Dog[]{new Dog(),new Dog(),new Dog()}
旺财 笨笨
② Dog[] ds=new Dog[3];
ds[o]=newDog();
name
name
name
ds[1]=new Dog();
ds[2]=new Dog();
ds[0].name=”旺财”;
对象
对象
对象
ds[1].name=”笨笨”;
③ Dog[] ds=new Dog[3];
ds[0]=a1;
0 1 2
ds[1]=a2;
ds[2]=a3;
ds[1].name=”旺财”;
ds
System.out.println(a2.name);
9. ②数组引用
Dog d1=new Dog();
d1.name=”旺财”;
Dog d2=new Dog();
name
d2.name=”旺财它哥”;
对象
Dog[] ds=new Dog[]{d1,d2};
ds[0].nane=”旺财二代”;
d1 d2
System.out.println(d1.name);
结果为旺财二代
Dos.path
10.d:/>java
有 则继续运行
没有
报错
main()
String[] 数组
准备外界参数
“A” “A A” ‘/’ “*”
初始化static(静态成员)
加载Test.class
有
没有
Class 不存在
结果
按classpath走
没有 有
D:/
classpath
找Test.exe文件
没有 java.exe
报错。没有此命令
有 java.exe
11.接受外界参数(String[] args)
12.在DDS中”*”是目录的意思。
13.封装:面向用户更简单,面向属性更安全。
14.java权限修饰符 public protectedprivate 置于类的成员定义前,用来限定其他对象对该类对象的访问权限。
Public 任何地方
Protected 在不同包的子类中可用
Default 只可以被同一个包内部的类访问
Private 只能访问类的内部
15. 封装的两个方法 set和get
16.private String name;
Public void setName(String n){
name=n;
}
Public voidgetName(){
return name;
}
private String name1;
private String name2;
public void setName(String n1,String n2){
name1=n1;
name2=n2;
}
Public void getName(){
return (name1+name2);
}
安全验证
publicvoid setXy(int x1,int y1){
if(x1<=-1|| y1<=-1){
System.out.println("wrong```");
}else{
x=x1;
y=y1;
}
数组的封装:
private String[] colors=new String[10];
publicvoid setColors(String[] cs){
colors=cs;
}
publicString[] getColors(){
return colors;
}
public void addcolor(int index,String color){
colors[index]=color;
}
publicint getColorsSize(){
return colors.length;
}
Boolean类型的封装:
public boolean state;
publicvoid setState(boolean s){
state=s;
}
publicboolean isState(){
return state;
}
- java实训第六次课后实训——数组
- java实训第四次课后笔记—函数
- 第六次课后作业——总结
- java实训第五次课后实训——面向对象
- java实训第七次课后笔记——继承、多态
- 第六次课后作业
- 第六次课后作业
- 第六次课后作业
- 第六次课后作业
- 第六次课后作业
- 第六次课后作业
- 第六次课后作业
- java第八次课后笔记——抽象类、接口
- C++第六次实验——数组的操作。
- C++第六次实验——数组操作
- c++第六次实验——数组合并
- 第六次上机实验——数组合并
- 第六次实验——数组的操作
- PHP5生成图形验证码(有汉字)
- How to cleanup orphaned Data Pump jobs in DBA_DATAPUMP_JOBS ?
- 构造函数的实现
- HashMap和ConcurrentHashMap
- 如何使用mingw-get命令更新MinGW下的GCC
- java实训第六次课后实训——数组
- HDU-1875-畅通工程再续
- 左移<<和右移
- 使用openlayers开源组件建立地图应用
- SQLITE3 使用总结
- 软链接和硬链接
- Android 动态加载APK--代码安装、获取资源及Intent调用已安装apk
- 随机提取中位数
- HDU 2037 今年暑假不ac