1.将一个字符串逆序输出 例如: abcd --> dcba
package com.ffyc.javaoop.day08.HM;
/*
.将一个字符串逆序输出 例如: abcd --> dcba
*/
public class Demo1 {
public static void main(String[] args) {
String s = "abcd";
char[] c = s.toCharArray();
String s1 = "";
for (int i = c.length-1; i >=0 ; i--) {
s1+=c[i];
}
System.out.println(s1);
}
}
2.统计一个字符串中出现的大写字母,小写字母各自的个数
package com.ffyc.javaoop.day08.HM;
/*
统计一个字符串中出现的大写字母,小写字母各自的个数
*/
public class Demo2 {
public static void main(String[] args) {
String s = "ABUghgGUnks";
byte[] b = s.getBytes();
int dx = 0;
int xx = 0;
for (int i = 0; i < b.length; i++) {
if(b[i]>=65&&b[i]<=90){
dx++;
}else if(b[i]>=97&&b[i]<=122){
xx++;
}
}
System.out.println("大写字母个数:"+dx+"\n小写字母个数"+xx);
}
}
3.判断一个字符串是否对称,例如"abccba"
package com.ffyc.javaoop.day08.HM;
/*
判断一个字符串是否对称,例如"abccba"
*/
public class Demo3 {
public static void main(String[] args) {
String s = "abccba";
char[] c = s.toCharArray();
String s1 = "";
String s2