java4

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java4相关的知识,希望对你有一定的参考价值。


public class xt6_1 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str1="Java技术学习班20070326";
System.out.println(str1.substring(9));
}

}

技术分享

public class xt6_2 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str1="MLDN JAVA";
System.out.println(str1.substring(0,5)+"J2EE");
}

}

技术分享


public class xt6_3 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str1="Java技术学习班20070326";
System.out.println(str1.charAt(7));
}

}

技术分享


public class xt6_4 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="Java技术学习班20070326";
String newStr=str.replaceAll("0","");
System.out.println(newStr);
}

}

技术分享

 


public class xt6_5 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="Java 技术学习班 20070326 MLDN 老师";
String newStr=str.replaceAll(" ","");
System.out.println(newStr);
}

}

技术分享

 


public class xt6_6 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str1="140105199504202917";
System.out.println(str1.substring(6,14));
}

}

技术分享

class Book {
private String name;
private int no = 000;
private float price;
private static int count = 0;
private static int sumCnt = 0;
public Book(String name, float price, int count) {
this.sumCnt = this.sumCnt + count;
this.no = sumCnt;
this.name = name;
this.price = price;
this.count = count;
}
public void print() {
System.out.println("书名: " + this.getName() + "\t" + "编号: "
+ this.getNo() + "\t" + "价格: " + this.getPrice() + "\t"
+ "册数: " + this.getCount());
System.out.println("\n" + "总册书为:" + sumCnt);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public static int getCount() {
return count;
}
public static void setCount(int count) {
Book.count = count;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public static int getSumCnt() {
return sumCnt;
}
public static void setSumCnt(int sumCnt) {
Book.sumCnt = sumCnt;
}
}

public class Practice {
public static void main(String args[]) {
Book book1 = new Book("数学", 79.8f, 10);
book1.print();
Book book2 = new Book("语文", 20.5f, 4);
book2.print();
Book book3 = new Book("英语", 36.0f, 6);
book3.print();
Book book4 = new Book("汉语", 26.8f, 10);
book4.print();
}
}

技术分享

以上是关于java4的主要内容,如果未能解决你的问题,请参考以下文章