package demo05;
public class Zy01 {
public static void main(String[] args) {
String s = "打劫!我有枪";
exchange(s);
}
private static void exchange(String s) {
String[] str = {"枪"};
for (int i = 0; i < str.length; i++) {
if (s.contains(str[i])) {
s = s.replace(str[i], "*");
System.out.println(s);
}
}
}
}
package demo05;
public class Zy02 {
public static void main(String[] args) {
String s = "北京欢迎你";
String s1 = s.replaceAll("北京", "郑州");
String s2=s1.replaceAll("你", "你们");
System.out.println(s2);
}
}
package demo05;
public class Zy03 {
public static void main(String[] args) {
String s3 = "面向对象是以对象为核心..编程思想";
char[] c = s3.toCharArray();
char[] a = {c[0],c[c.length-1]};
String a2 = String.copyValueOf(a);
System.out.println(a2);
}
}
package demo05;
public class Zy04 {
public static void main(String[] args) {
double d=3.1415926;
System.out.println("d = " + d);
String s = String.valueOf(d);
System.out.println("字符串s的值: " + s);
}
}
package demo05;
public class Zy05 {
public static void main(String[] args) {
String s="qwqe";
if (s.length()>0) {
System.out.println("此字符串不为空");
System.out.println("s = " + s.charAt(0));
System.out.println("字符串的长度为" + s.length());
System.out.println("第一个字符" + s.charAt(0));
}else {
s="hello word";
System.out.println("此字符串为空赋值为 hello word");
System.out.println("字符串的长度为" + s.length());
System.out.println("第一个字符" + s.charAt(0));
}
}
}
package demo05;
public class Zy06 {
public static void main(String[] args) {
String s= "abca";
System.out.println("a的下标为" + s.indexOf("a"));
System.out.println("a的下标为" + s.lastIndexOf("a"));
if (s.equals(s.charAt(0)) == s.equals(s.charAt(s.length()-1))) {
s="*bc*";
System.out.println("s = " + s);
}
}
}
package demo05;
public class Zy07 {
public static void main(String[] args) {
int i1 = Integer.parseInt("123");
System.out.println(i1);
Integer inte1 = new Integer(i1);
System.out.println(inte1);
int i = 10;
String str3 = String.valueOf(i);
System.out.println(str3);
String str4 = "" + i;
System.out.println(str4);
}
}