5 2)char last = greeting.charAt(4); //提取“Hello”字符串的第4个字符‘o’
Java语言程序设计
5.1.3 String类
3. 字符串的修改、连接和替换 1)字符串连接 String str1 = “abc”; String str2 = str1.concat(“cde”); //str2=“abccde” 相当于 String str2= str1 + “cde”; 2)替换子串 String str3 = str2.replace(“c”,”33”): // str3 = “ab3333de”; String str3 = str2.replace(“cc”,”33”): // str3 = “ab33de”;
public class test{ public static void main(String[] args) { System.out.println(max(4,3)); System.out.println(max(5,7,2)); }
static int max ( int a , int b ) { return a > b ? a : b ; }
{ A.a = new A(); B.b = new B(); a.f(); a.h(); b.f();
} }
Java语言程序设计
5.3 重载方法
方法的重载是指同一个类中定义多个名称相同、但 参数不同的方法。
Java虚拟机能根据传递给方法的参数,自动选择合 适的重载方法。
Java语言程序设计
重载的简单例子
static int max ( int a , int b, int c ) { int t ; t = max ( a , b ) ; return max ( t , c ) ;