02-java语言基础-数组向量字符串.ppt
文本预览下载声明
第二章Java 语言基础;Contents;复合数据类型 ;复合数据类型;复合数据类型;复合数据类型;复合数据类型;两种类型变量的不同处理;关于对象和对象的“引用”; 数组和字符串 ;第一节 数组 ;数组概述 ;数组概述 ;一维数组 ;a null ; 所有的引用类型都需要用new来初始化;一维数组的创建;public class Test{
public static void main(String args[]){
int [] s;
s=new int [5];
for (int i=0;i5;i++){
s[i]=2*i+1
}
}
};一维数组;一维数组;一维数组;一维数组的创建; 注意:元素为引用类型的数组中的每一个元素都需要实例化。;一维数组的初始化;一维数组的初始化;一维数组的初始化;当用new创建了一个对象时,系统为对象中的变量进行了初始化,即不但为变量分配了相应的存储单元,还设置了变量所属类型的相应初值,这样就避免发生变异错误。;一维数组的初始化;一维数组;一维数组;一维数组;数组边界;数组边界;数组边界;;;二维数组 ;二维数组 ;二维数组 ;二维数组 ;二维数组 ;二维数组 ;第二节 字符串;字符串概述 ;字符串概述 ;字符串概述;1、声明字符串变量;String类 - 1.字符串的创建 ;String类 - 1.字符串的创建 ;String类 - 1.字符串的创建 ;小结;字符串运算;例;class Order{
public static void main (String args[ ]){
int a=34, b=21, c=27, t;
if (ab) { t=a; a=b; b=t; }
if (bc) { t=b; b=c; c=t; }
if (ab) { t=a; a=b; b=t; }
System.out.println(The order is+
a+,+b+,+c);
}
};class Order{
public static void main (String args[ ]){
int a=34, b=21, c=27, t;
if (ab) { t=a; a=b; b=t; }
if (bc) { t=b; b=c; c=t; }
if (ab) { t=a; a=b; b=t; }
System.out.println (a + b + c);
}
};class Order{
public static void main (String args[ ]){
int a=34, b=21, c=27, t;
if (ab) { t=a; a=b; b=t; }
if (bc) { t=b; b=c; c=t; }
if (ab) { t=a; a=b; b=t; }
System.out.println(The order is + a + b + c);
}
};String类 - 2.String类的常用方法 ;String类 - 2.String类的常用方法 ;String类 - 2.String类的常用方法 ;String类 - 2.String类的常用方法 ;String类 - 2.String类的常用方法 ;String类 - 2.String类的常用方法 ;String类 - 2.String类的常用方法 ;0 ;String类 - 3.= = 与 equals( )方法 ;class StringTest2 {
public static void main (String args[ ]) {
String s1 = This is the second string.;
String s2 = This is the second string.;
String s3 = new String (This is the
second string.);
String s4 = new String ( s1 ); String s5 = s1;
;StringBuffer类;StringBuffer类 – 创建;StringBuffer类 - 常用的方法;StringBuffer类 - 常用的方法;StringBuffer类 - 常用的方法;StringBuffer类 - 常用的方法;向量(Vecto
显示全部