public class M1 {
public static void main(String[] args) {
String s = "startWITH";
System.out.println(s.toLowerCase());//大写转小写
System.out.println(s.toUpperCase());//小写转大写
}
}
public class M2 {
public static void main(String[] args) {
String s = "abcdefg";
System.out.println(new StringBuffer(s).reverse().toString());
}
}
import java.util.Scanner;
public class M3 {
public boolean dc(String str) {
boolean flag = false;
if (str != null && str.length() > 0) {
if(str.contains(new StringBuffer(str).reverse())) {
System.out.println("相同");
flag = true;
return flag;
}
}
return flag;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串");
String str = sc.next();
M5 t = new M5();
boolean flag = t.dc(str);
System.out.println(flag);
}
}
113
ere
qqq
yyui
public class M4 {
public static void main(String[] args) {
String s = "113@ ere qqq yyui";
String[] arr = s.split("@?\\s+");
for (String x : arr) {
System.out.println(x);
}
}
}
public class M5 {
public static void main(String[] args) {
String s = "To be or not to be";
String[] arr = s.split(" ") ;
for (String x : arr) {
System.out.print(new StringBuffer(x).reverse()+" ");
}
}
}
zhangsan 18 090728
public class M6 {
public static void main(String[] args) {
String s = "name=zhangsan age=18 classNo=090728";
String[] arr = s.split(" ");
for (String x : arr) {
String[] temp = x.split("\\s?[a-zA-Z]+=");
System.out.println(temp[1]);
}
}
}
//String s = {"nba","abc","cba","zz","qq","haha"}
public class M7 {
public static void main(String[] args) {
String[] arr = { "nba", "abc", "cba", "zz", "qq", "haha" };
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length-1; j++) {
if("arr[j]".compareTo("arr[j+1")>0) {
String temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
}
System.out.println(Arrays.toString(arr));
}
}
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dNchYA7s-1594901815759)(C:\Users\lx\AppData\Local\Temp\1594870869860.png)]
//String s = "nbaernbatynbauinbaopnba"
public class M7 {
public static void main(String[] args) {
String s = "nbaernbatynbauinbaopnba";
int count = 0;
while(s.contains("nb")) {
int index= s.indexOf("nb");
s = s.substring(index+2,s.length());
count++;
System.out.println(s);
}
System.out.println(count);
}
}
public class M10 {
public static String m10(String s) {
int start = 0;
int end = 0 ;
for (int i = 0; i <s.length(); i++) {
if(s.charAt(i)!=' ') {
start=i;
break;
}
}
for (int i =s.length()-1; i>=0; i--) {
if(s.charAt(i)!=' ') {
end = i;
break;
}
}
System.out.println(start+","+end);
if(start==end) {
return "";
}
return s.substring(start, end+1);
}
public static void main(String[] args) {
String s = " i love you ";
String s1 = m10(s);
System.out.println(s1);
}
}
import java.util.ArrayList;
public class M9 {
public static ArrayList<String> fun(String a,String b) {
ArrayList<String> list = new ArrayList();
//长字符串
String s1 = a.length()>b.length()?a:b;
//短字符串
String s2 = a.length()<=b.length()?a:b;
for (int i = 0; i < s2.length(); i++)
{
System.out.println("当前截取" + i + "个字符");
int start = 0;
int end = s2.length() - i;
while (end != s2.length() + 1)
{
System.out.println(start + "," + end);
String sub = s2.substring(start, end);
System.out.println(sub);
if (s1.contains(sub)) {
list.add(sub);
}
start++;
end++;
}
}
return list;
}
public static void main(String[] args) {
String s1 = "asdfvxjnmkjk";
String s2 = "fvjadaskjk";
ArrayList<String> list = fun(s1,s2);
System.out.println(list);
}
}