码迷,mamicode.com
首页 > 编程语言 > 详细

java4

时间:2016-03-31 20:22:26      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:


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

标签:

原文地址:http://www.cnblogs.com/zp742601689/p/5342434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!