一.
public class DaJie {
public static void main(String[] args) {
String a = "打劫!我有枪";
dj(a);
}
private static void dj(String a) {
String [] stu = {"枪"};
for (int i = 0; i < stu.length; i++) {
if (a.contains(stu[i])){
a = a.replace(stu[i],"*");
System.out.println(a);
}
}
}
}
二.
public class BeiJing {
public static void main(String[] args) {
String a = "北京欢迎你";
String[] str = {"北京"};
String[] str1 = {"你"};
for (int i = 0; i < str.length; i++) {
if(a.contains(str[i])){
a = a.replace(str[i],"郑州");
a = a.replace(str1[i],"你们");
System.out.println(a);
}
}
}
}
三.
public class SiXiang {
public static void main(String[] args) {
//定义的字符串
String a = "面向对象是以对象为核心..编程思想";
//用for循环获取下标
for (int i = 0; i < a.length(); i++) {
}
//charAt是获取字符串第i个字符
System.out.println(a.charAt(0));
System.out.println(a.charAt(a.length()-1));
}
}
四.
public class San {
public static void main(String[] args) {
double a=3.1415926;
System.out.println("a = " + a);
String str = String.valueOf(a);
System.out.println("字符串str 的值: " + str);
}
}
五.
public class Kong {
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));
}
}
}
六.
ublic class WeiZhi {
public static void main(String[] args) {
String a= "abca";
System.out.println("a的下标为" + a.indexOf("a"));
System.out.println("a的下标为" + a.lastIndexOf("a"));
if (a.equals(a.charAt(0)) == a.equals(a.charAt(a.length()-1))) {
a="*bc*";
System.out.println("a = " + a);
}
}
}
七.
public class IntAndInteger {
public static void main(String[] args) {
int num = 123;
Integer a = new Integer(num);
System.out.println(a.toString());
Integer a2 = new Integer("123");
System.out.println(a2.toString());
Boolean b1 = new Boolean("true11");
System.out.println(b1);
int c = 11;
// 字符串连接符转换
String str = c + "";
Integer d = new Integer(11);
System.out.println(str);
String str1 = "123";
Integer e1 = Integer.parseInt(str1);
System.out.println("e1 = " + e1);
}
}