A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王震阳老师   /  2014-4-30 11:23  /  29244 人查看  /  452 人回复  /   2 人收藏 转载请遵从CC协议 禁止商业使用本文

看看设么么
回复 使用道具 举报
本帖最后由 hhmm665544 于 2014-4-30 19:33 编辑

第一题答案

Test1.rar

839 Bytes, 阅读权限: 100, 下载次数: 1

回复 使用道具 举报
看看是什么
回复 使用道具 举报
先领题,希望自己能够完成啊!
回复 使用道具 举报
Union 高级黑马 2014-4-30 18:05:42
85#
再看一遍!
回复 使用道具 举报
这个必须要
回复 使用道具 举报
什么问题?
回复 使用道具 举报
回复回复
回复 使用道具 举报
import java.util.*;
public class Demo {
        public static void main(String[] args) {
               number();
            }
                public static void number(){
               
               
                 int abcnumber=0;           //英文字母个数
                int spacenumber=0;         //空格键个数
                int intumber=0;            //数字个数
                int Othernumber=0;         //其他字符个数
                                 System.out.println("请输入字符");
                Scanner scan=new Scanner(System.in);
                String str=scan.nextLine();
                char[] ch = str.toCharArray();

                for(int i=0;i<ch.length;i++){
                 if(Character.isLetter(ch[i])){

                           abcnumber++;
                        }
                  else if(Character.isDigit(ch[i])){

                                intumber++;
                        }
                   else if(Character.isSpaceChar(ch[i])){

                                spacenumber++;
                        }
                   else{

                           Othernumber++;
                    }
                }
                System.out.println("字母个数 ="+abcnumber);
                System.out.println("数字个数="+intumber);
                System.out.println("空格个数="+spacenumber);
                System.out.println("其他字符个数="+Othernumber);

                }
}

评分

参与人数 1技术分 +2 收起 理由
王震阳老师 + 2 赞一个!

查看全部评分

回复 使用道具 举报
求题目   黑马程序员
回复 使用道具 举报
看一下什么题型
回复 使用道具 举报
看一下         
回复 使用道具 举报
技术分:D:lol
回复 使用道具 举报
领取题目
回复 使用道具 举报
我都看看
回复 使用道具 举报
  1. import java.util.Scanner;

  2. /*
  3. 题目一:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
  4. */

  5. class  WuYiDemo1
  6. {
  7.         public static void main(String[] args)
  8.         {
  9.                 int wordSum = 0 ;
  10.                 int spaceSum = 0;
  11.                 int numSum = 0 ;
  12.                 int otherSum = 0;
  13.                 System.out.print("请输入要统计的字符串:");
  14.                 Scanner sc = new Scanner(System.in);
  15.                 String str = sc.nextLine();
  16.                
  17.                 for (int i = 0 ; i<str.length();i++ )
  18.                 {
  19.                         int ch = str.codePointAt(i);
  20.                        
  21.                         if (ch>=48 && ch <=57)
  22.                         {
  23.                                 numSum++;
  24.                         }
  25.                         else if (ch>=65&&ch<=90)
  26.                         {
  27.                                 wordSum++;
  28.                         }
  29.                         else if (ch>=97&&ch<=122)
  30.                         {
  31.                                 wordSum++;
  32.                         }
  33.                         else if (ch==32)
  34.                         {
  35.                                 spaceSum++;
  36.                         }
  37.                         else
  38.                                 otherSum++;

  39.                 }
  40.                
  41.                
  42.                 System.out.println("字符串中空格个数:"+spaceSum+"  "+"字母个数:"+wordSum+"  "+"数字个数:"+numSum+"  "+"其他字符个数:"+otherSum);
  43.         }
  44. }
复制代码


评分

参与人数 1技术分 +2 收起 理由
王震阳老师 + 2 赞一个!

查看全部评分

回复 使用道具 举报
先看看,
回复 使用道具 举报
什么题目?
回复 使用道具 举报
  1. package Practice;

  2. class CharacterSorter
  3. {
  4.         public static String CharacterSort(String s)
  5.         {
  6.                 int[] count=new int[4];
  7.                 char[] chs=s.toCharArray();
  8.                 for(char ch:chs)
  9.                 {
  10.                         if(ch==' ')count[0]++;
  11.                         else if ('0'<=ch&ch<='9')
  12.                                         count[1]++;
  13.                         else if(('a'<=ch&ch<='z')||
  14.                                         ('A'<=ch&ch<='Z'))
  15.                                 count[2]++;
  16.                         else
  17.                                 count[3]++;
  18.                 }
  19.                 int sum=count[0]+count[1]+count[2]+count[3];
  20.                 return "字符总数:"+sum+"个,空格数个数:"+count[0]+"个,数字个数:"
  21.                 +count[1]+"个,字母个数:"+count[2]+"个,其他字符个数:"+count[3];
  22.         }
  23.         }
  24. public class TestCharacterSorter
  25. {
  26.         public static void main(String[] args) {
  27.                 // TODO Auto-generated method stub
  28. String str=" sd  fhg ui sd 14 6SFG5434/.x,.a";
  29. System.out.println(CharacterSorter.CharacterSort(str));
  30.         }
  31. }
  32. //打印结果
  33. //字符总数:32个,空格数个数:7个,数字个数:7个,字母个数:14个,其他字符个数:4。
复制代码

评分

参与人数 1技术分 +1 收起 理由
王震阳老师 + 1 包名和变量名不符合命名规范。.

查看全部评分

回复 使用道具 举报
我来看看
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马