一串字符串算出其中大写字母,小写字母和数字的个数,并将这个结果按倒序输出

qq_37944267 qq_37944267 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想请问我将Int型用valueof转换字符类型,又用tochararray转化为字符数组,从而利用数组来实现倒序输出,即例如12,输出为21,但是结果不对,我试了一下,假如用过tocharrarry,我用length去测长度结果显示为1,是不是这样,假如数字个数为14个,把他给字符数组后,不是ch【0】=4,ch【1】=1,而是ch【0】=14,那么应该怎么调整呢
import java.util.*;
public class DING2 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = 0;
int b = 0;
int num = 0;
char temp,temp1;
String a1,b1,num1;
String s;
Scanner r = new Scanner(System.in);
System.out.println("please input something");
s = r.next();
System.out.println(s+" ");
char[] ch = s.toCharArray();
for(int i=0;i<ch.length;i++){
if(ch[i]>'a'&&ch[i]<'z')
a++;
if(ch[i]>'A'&&ch[i]<'Z')
b++;
if(ch[i]<'9'&&ch[i]>'0')
num++;
}
System.out.println(+a+" "+b+" "+num);
a1 = String.valueOf(a);
b1 = String.valueOf(b);
num1 = String.valueOf(num);
char []ch1 = a1.toCharArray();
int j = ch1.length;
if(j%2==0&&j>10)
for(int i=0;i<ch1.length/2;i++){
temp = ch1[i];
ch1[i] = ch1[j-i-1];
ch1[j-i-1] = temp;
}
else if(j>10){
for(int i=0;i<(ch1.length-1)/2;i++){
temp1 = ch1[i];
ch1[i] = ch1[j-i-1];
ch1[j-i-1] = temp1;
}
}

System.out.print("the num is");
for(int i=0;i<ch1.length;i++)
System.out.print(+ch1[i]);
System.out.println();

char []ch2 = b1.toCharArray();
temp = 0;temp1 = 0;
int k = ch2.length;
if(k%2==0&&k>10)
for(int i=0;i<ch2.length/2;i++){
temp = ch2[i];
ch2[i] = ch2[k-i-1];
ch2[k-i-1] = temp;
}
else if(k>10){
for(int i=0;i<(ch2.length-1)/2;i++){
temp1 = ch2[i];
ch2[i] = ch2[k-i-1];
ch2[k-i-1] = temp1;
}
}
System.out.print("the num is");
for(int i=0;i<ch2.length;i++)
System.out.print(+ch2[i]);
System.out.println();

temp = 0;temp1 = 0;
char []ch3 = num1.toCharArray();
int l = ch3.length;
if(l%2==0&&l>10)
for(int i=0;i<ch3.length/2;i++){
temp = ch3[i];
ch3[i] = ch3[l-i-1];
ch3[l-i-1] = temp;
}
else if(l>10){
for(int i=0;i<(ch3.length-1)/2;i++){
temp1 = ch3[i];
ch3[i] = ch3[l-i-1];
ch3[l-i-1] = temp1;
}
}
System.out.print("the num is");
for(int i=0;i<ch3.length;i++)
System.out.print(+ch3[i]);
System.out.println();
}
}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
qq_37944267
Eclipse 58,440 成员 49,457 内容