class="article_content clearfix">
class="htmledit_views">
class="dp-highlighter bg_java" style="padding:1px 0px 0px; font-family:Consolas,"Courier New",Courier,mono,serif; background-color:rgb(231,229,220); width:742.5px; overflow-x:auto; overflow-y:hidden; position:relative; color:rgb(69,69,69); margin:18px 0px!important">class="dp-j" style="padding:0px; list-style-position:initial; border-top:none; border-right:1px solid rgb(231,229,220); border-bottom:none; border-left:none; background-color:rgb(255,255,255); color:rgb(92,92,92); margin:0px 0px 1px 45px!important">
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important">class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">package excise;
- class="comment" style="margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit">/*输入一行字符,分别统计出其中英文字母
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important">class="comment" style="margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit"> 、空格、数字的个数*/
- class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">import java.util.Scanner;
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important">class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">public class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">class T007 {
- class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">public class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">static class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">void main(String args[]){
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">int num=class="number" style="margin:0px; padding:0px; border:none; color:rgb(192,0,0); background-color:inherit">0,chartra=class="number" style="margin:0px; padding:0px; border:none; color:rgb(192,0,0); background-color:inherit">0,blak=class="number" style="margin:0px; padding:0px; border:none; color:rgb(192,0,0); background-color:inherit">0,other=class="number" style="margin:0px; padding:0px; border:none; color:rgb(192,0,0); background-color:inherit">0;
- Scanner s=class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">new Scanner(System.in);
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> System.out.println(class="class="tags" href="/tags/STRING.html" title=string>string" style="margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"请输出字符创");
- String result=s.nextLine();
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">char x[]=result.toCharArray();
- class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">for(class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">int i=class="number" style="margin:0px; padding:0px; border:none; color:rgb(192,0,0); background-color:inherit">0;i<x.length;i++){
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">if(Character.isDigit(x[i])){
- num++;
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> }class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">else class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">if(Character.isLetter(x[i])){
- chartra++;
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> }class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">else class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">if(Character.isSpace(x[i])){
- blak++;
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> }
- class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">else{
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> other++;
- }
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> System.out.println(x.length);
- }
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> System.out.println(class="class="tags" href="/tags/STRING.html" title=string>string" style="margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"数字的个数是"+num);
- System.out.println(class="class="tags" href="/tags/STRING.html" title=string>string" style="margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"字符的个数是"+chartra);
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> System.out.println(class="class="tags" href="/tags/STRING.html" title=string>string" style="margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"空值的个数是"+blak);
- System.out.println(class="class="tags" href="/tags/STRING.html" title=string>string" style="margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"其他的个数是"+other);
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> }
- }
但是请注意,,我们在使用的时候因为是要在android studio上面使用的所以需要修改
class="dp-j" style="font-family:Consolas,"Courier New",Courier,mono,serif; white-space:pre-wrap; padding:0px; list-style-position:initial; border-top:none; border-right:1px solid rgb(231,229,220); border-bottom:none; border-left:none; color:rgb(92,92,92); margin:0px 0px 1px 45px!important">
- Scanner s=class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">new Scanner(System.in);
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> System.out.println(class="class="tags" href="/tags/STRING.html" title=string>string" style="margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"请输出字符创");
- String result=s.nextLine();
- class="alt" style="margin-left:40px; list-style:decimal; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(108,226,108); color:inherit; line-height:18px; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; padding:0px 3px 0px 10px!important"> class="keyword" style="margin:0px; padding:0px; font-weight:bold; background-color:inherit; color:rgb(0,102,153); font-size:14px; word-wrap:normal; border:none">char x[]=result.toCharArray();
修改后的主要是可以自己定义的字符串
String s="daold dkajoe 39 sdied zhogn 中的.dk dodkdkeo o "; char x[]=s.toCharArray();