public class Demo61 { public static void main(String[] args) {
class Book { private String name; private int id; private float price; private static int num=3; private static int count =0; public Book(){ count++; this.id = count; } public Book(int id){ this.id = id; } public int getId(){ return this.id; } public Book(String name,float price){ this.name = name; this.price = price; this.num = num; } public void setName(String name){ this.name = name; } public String getName(){ return this.name; } public void setPrice(float price){ this.price = price; } public float getPrice(){ return this.price; } public void setNum(int num){ this.num = num; } public int getNum(){ return this.num; } } public class Lake{ public static void main(String args[]){ Book book[] = new Book[6]; book[0] = new Book("java教程 ",99.9f); book[1] = new Book("java web教程",69.9f); book[2] = new Book("java EE教程",67.9f); book[3] = new Book("android教程 ",56.8f); book[4] = new Book("Mysql教程 ",56.5f); book[5] = new Book("oracle教程",78.7f); for (int i=0;i<book.length;i++ ){ System.out.println("编号:"+new Book().getId()+"\t书名:"+book[i].getName()+ "\t价格:"+book[i].getPrice()+"\t数量:"+book[i].getNum()); } System.out.println("图书总量为:"+(new Book().getId()-1)*book[1].getNum()); } }
String str1 = "Java技术学习班20070326"; System.out.println(str1.substring(9, 17)); String str2 = "MLDN Java"; System.out.println(str2.replaceAll("JAVA", "J2EE"));// 如果寻找的Java不在str2里面,则不替换 String str3 = "Java技术学习班20070326"; System.out.println(str3.charAt(8)); String str4 = "Java技术学习班20070326"; System.out.println(str4.replace("0", "")); String str5 = "Java技术学习班 20070326 MLDN 老师"; System.out.println(str5.replace(" ", "")); String str6 = "320821199410055500"; System.out.println(str6.substring(6, 17)); } }