java实现输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

news/2024/7/4 1:43:00 标签: string, class
class="baidu_pl">
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">
  1. 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;  
  2. class="comment" style="margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit">/*输入一行字符,分别统计出其中英文字母  
  3. 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"> 、空格、数字的个数*/  
  4. 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;  
  5. 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 {  
  6.     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[]){  
  7. 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;  
  8.         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);  
  9. 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">"请输出字符创");  
  10.         String   result=s.nextLine();  
  11. 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();  
  12.         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++){  
  13. 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])){  
  14.                num++;  
  15. 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])){  
  16.                chartra++;  
  17. 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])){  
  18.                blak++;  
  19. 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">           }  
  20.            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{  
  21. 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++;  
  22.            }  
  23. 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);  
  24.         }  
  25. 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);  
  26.         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);  
  27. 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);  
  28.         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);  
  29. 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">    }  
  30. }  

但是请注意,,我们在使用的时候因为是要在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">
  1. 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);  
  2. 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">"请输出字符创");  
  3.         String   result=s.nextLine();  
  4. 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();


http://www.niftyadmin.cn/n/862158.html

相关文章

有1,2,3,4四个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?

public class MainActivity extends AppCompatActivity {int i0; //保存百位上的数int j0; //保存十位上的数int k0; //保存各位上的数int t0; //保存数字个数TextView text,ge;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstance…

java顺时针、逆时针打印矩阵

public class SnakeMatrix {/*** 定义矩阵的阶数*/private int n;//填充矩阵的值private int k 1;private int[][] data;/*** 定义矩阵移动的方向*/public enum Direction {left, right, up, down,}SnakeMatrix(int n) {this.n n;data new int[n][n];}public void clockwise…

错误 330 (net::ERR_CONTENT_DECODING_FAILED):未知错误解决办法

错误 330 (net::ERR_CONTENT_DECODING_FAILED)&#xff1a;未知错误。 网页330错误解决办法|关闭GZIP错误 330 (net::ERR_CONTENT_DECODING_FAILED)&#xff1a;未知错误。采用未知的压缩格式采用不支持的编码 解决办法 一般出现这个原因都是GZIP跟某个PHP文件或者某个网页发生…

Android发展趋势分析

继手机、平板电脑后&#xff0c;汽车成Android下一重点开拓领域 其实我们来回顾一下Android的发展趋势&#xff0c;它从一个智能手机的OS为基础&#xff0c;一边学习和借鉴Apple的产品&#xff0c;一边吸纳合作手机厂商的贡献&#xff0c;不断地增加了各种各样的功能&#xff0…

Poechant 快速安装配置教程:Windows 7下Apache+MySQL+PHP开发环境

1、下载 今天在Windows 7下进行PHP环境搭建&#xff0c;首先需要下载PHP代码包和Apache与MySQL的安装软件包。 PHP版本&#xff1a;php-5.3.6-Win32-VC9-x86.zip 下载地址&#xff1a;http://windows.php.net/download/ &#xff08;注意一定要下载 thread safe 版本&#xf…

PHP的集成开发环境 -- Eclipse PHP Integrated Development Environment

Eclipse PHP Integrated Development Environment Win32版本的下载地址&#xff1a; http://www.eclipse.org/downloads/download.php?file/technology/epp/downloads/release/helios/R/eclipse-php-helios-win32.zip 中国科学技术大学源&#xff1a;University of Science an…

CardView是在安卓5.0提出的卡片式控件

compile com.android.support:cardview-v7:23.2.0 Cardview继承自FrameLayout&#xff0c;所以子控件布局规则和FrameLayout的一样&#xff0c;这个FrameLayout特殊点就是有rounded corner&#xff08;圆角&#xff09;和shadow&#xff08;阴影&#xff09;CardView的常用属…

Android 图片缓存处理

异步下载 / 本地缓存 异步下载 大家都知道&#xff0c;在android应用中UI线程5秒没响应的话就会抛出无响应异常&#xff0c;对于远程获取大的资源来说&#xff0c;这种异常还是很容易就会抛出来的&#xff0c;那么怎么避免这种问题的产生。在android中提供两种方法来做这件事情…