你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
AurevoirXavier - So they say,we are the dead.But we live love.
赞同来自: 浅唱10450704
fengyun12
赞同来自:
AustinGJ - 85后 IT 男
赞同来自: GALEX
要回复问题请先登录或注册
3 个回复
AurevoirXavier - So they say,we are the dead.But we live love.
赞同来自: 浅唱10450704
--来自网页客户端
fengyun12
赞同来自:
* 每日一练 20160503
* 用JAVA输入一串字符串,判断里面有多少汉字,字母,符号,数字,有多少个码,
* 多少个邦,并按顺序输出,然后把原字符串安装升序排序出来
*/
public void ex160503(){
Scanner sc=new Scanner(System.in); //创建标准输入流
System.out.println("请输入一串字符串(可以包含汉字,字母,符号,数字):");
String str=sc.nextLine(); //输入的原字符串
sc.close(); //关闭Scanner
String str1; //记录变动过程中的字符串
String str2; //记录汉字
char[] arr; //用数组记录汉字
int count1=str.length();
int count2;
System.out.println("原字符串长度为:"+count1);
str1=str.replaceAll("\\d", "");
System.out.println("数字的长度是:"+(count1-str1.length()));
count1=str1.length();
str1=str1.replaceAll("[a-zA-Z]", "");
System.out.println("字符的长度是:"+(count1-str1.length()));
count1=str1.length();
str2=str1.replaceAll("[^\\u4e00-\\u9fa5]", "");
str1=str1.replaceAll("[\\u4e00-\\u9fa5]", "");
System.out.println("汉字的长度是:"+(str2.length()));
System.out.println("符号的长度是:"+str1.length());
arr=str2.toCharArray();
count1=0;
count2=0;
for(char a:arr){
if(a=='码'){
count1++;
}
if(a=='邦'){
count2++;
}
}
System.out.println("码有"+count1+"个,邦有"+count2+"个");
//将原字符串按升序排列
arr=str.toCharArray();
Arrays.sort(arr);
str=String.copyValueOf(arr);
System.out.println(str);
}
--来自移动客户端
AustinGJ - 85后 IT 男
赞同来自: GALEX
import java.util.*;
public class Test {
/*
* 用Java输入一行字符串,判断里面有多少个数字,字母,符号,汉字,
* 判断里面有多少个"i",多少个"码",多少个"邦",并提取出来,按照顺序
* 输出,然后把原来的字符串按照升序排序
*
* */
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.nextLine();
char[] chr = str.toCharArray();
int countNum = 0;
int countLet = 0;
int countSim = 0;
int countCHN = 0;
int countI = 0;
int countMa = 0;
int countBang = 0;
for (int i = 0; i < chr.length; i++) {
if('0'<=chr[i]&&chr[i]<='9')
countNum++;
if(('a'<=chr[i]&&chr[i]<='z')||(('A'<=chr[i]&&chr[i]<='Z')))
{
countLet++;
if(chr[i]=='i'){
countI++;
System.out.println("在字符串的第"+(i+1)+"个位置找到第"+countI+"个"+chr[i]+";");
}
}
if(chr[i]>=19968&&chr[i]<=171941){
countCHN++;
if(chr[i]=='码'){
countMa++;
System.out.println("在字符串的第"+(i+1)+"个位置找到第"+countMa+"个"+chr[i]+";");
}
if(chr[i]=='邦'){
countBang++;
System.out.println("在字符串的第"+(i+1)+"个位置找到第"+countBang+"个"+chr[i]+";");
}
}
}
countSim=chr.length-(countNum+countLet+countCHN);
Arrays.sort(chr);
System.out.println("数字有:"+countNum+"个;\n"
+"字母有:"+countLet+"个;\n"
+"符号有:"+countSim+"个;\n"
+"汉字有:"+countCHN+"个;\n"
+"'i'有:"+countI+"个;\n"
+"'码'有:"+countMa+"个;\n"
+"'邦'有:"+countBang+"个;\n"
);
System.out.println("排序后的字符串为:");
for (char c : chr) {
System.out.print(c);
}
}
}
--来自网页客户端