聪聪工作室---JAVA入门小程序---增删查改的实现

import java.util.Scanner;

public class introduce {

public static void main(String[] args) {

String str="name:licongcong,from:hangzhou,like:meizi,job:chenxuyuan";

Scanner sc=new Scanner(System.in);

String shuru=sc.nextLine();

String name="name";

String from="from";

String like="meizi";

String job="chenxuyuan";

if(shuru.equals(name)){

System.out.println("licongcong");

}else if(shuru.equals(from)){

System.out.println("hangzhou");

}else if(shuru.equals(like)){

System.out.println("meizi");

}else if(shuru.equals(job)){

System.out.println("chenxuyuan");

}else{

System.out.println("l do not what you say.Are you kidding?");

}

//插入

insert();

delete();

replace();

System.out.println("Wonderful!你已经完美解决了这个问题!");

}

private static void replace() {

// TODO Auto-generated method stub

String str ="name:licongcong,from:hangzhou,like:meizi,job:chenxuyuan" , str22;//定义str11,str22

String regex = "cong" , substr="hum";//准备替换的regex,替换成 hum

System.out.println("改之前的: " + str);

str = str.replaceAll(regex, substr);    //把cong全都替换成hum

System.out.println("改之后的: " + str);

}

private static void delete() {

// TODO Auto-generated method stub

StringBuffer str = new StringBuffer("name:licongcong,from:hangzhou,like:meizi,job:chenxuyuan");

System.out.println("删除之前:" + str);

str.delete(5, 15);

System.out.println("删除之后: " + str);

}

private static void insert() {

// TODO Auto-generated method stub

StringBuffer str = new StringBuffer("name:licongcong,from:hangzhou,like:meizi,job:chenxuyuan");

System.out.println("插入之前: "+str);

str.insert(16, "l am very hum!");

System.out.println("插入语句:"+str);

}

}


聪聪工作室---JAVA入门小程序---增删查改的实现_第1张图片
聪聪工作室---JAVA入门小程序---增删查改的实现_第2张图片

你可能感兴趣的:(聪聪工作室---JAVA入门小程序---增删查改的实现)