zoukankan      html  css  js  c++  java
  • 软件测试第二次作业(1)

    package cn.lin.mju;

     

    public class Action {

         public void findWord(String str){//划分单词

                String[] arrayWord =str.split(" ");

                Action a = new Action();

                a.frequency(arrayWord);

            }

            public void frequency(String[] arrayWord){

                String[] word = new String[arrayWord.length];//存放遍历过的单词

                int time[]=new int[arrayWord.length];//存放记录单词出现次数

                boolean t = true;

                for(int i=0;i<arrayWord.length;i++){

                    for(int j=0;j<arrayWord.length;j++){//遍历已遍历过的单词表

                        if(arrayWord[i].equals(word[j])){

                            System.out.println("单词重复!!!");

                            t=false;//如果单词重复则跳过

                        }

                    }

                    if(t==true){//单词初始次数为1

                        word[i]=arrayWord[i];

                        time[i]=1;

                        for(int j=i+1;j<arrayWord.length;j++){//遍历字符串,记录次数

                            if(arrayWord[i].equals(arrayWord[j])){

                                time[i]++;

                            }

                        }

                    }

                }

                for(int i = 0;i<arrayWord.length;i++){//遍历输出次数

                    if(word[i]!=null){

                        System.out.println("单词:"+word[i]+"出现了"+time[i]+"次。");

                    }

                }

            }

     

    }

    package cn.lin.mju;

     

    import java.util.Scanner;

     

    public class View {

         public View(){

                Scanner input =new Scanner(System.in);

                System.out.println("请输入字符串,单词用空格隔开,回车结束:");

                String str=input.nextLine();

                Action a = new Action();

                a.findWord(str);

            }

     

    }

    package cn.lin.mju;

     

    public class Main {

         /**

         * @param args

         */

        public static void main(String[] args) {

            // TODO Auto-generated method stub

            View v = new View();

        }

     

    }

  • 相关阅读:
    中断和异常
    MATLAB总结二
    关于在写第一个模式识别大作业中遇到的几个问题的总结
    学习QT——GUI的基础用法(2)
    Matlab练习——rpy2tr函数与自己实现的ZYX欧拉角的结果不同的问题
    PHP之文件的锁定、上传与下载
    PHP之文件目录基础操作
    PHP之会话控制小结
    PHP之curl
    PHP之数组函数归类
  • 原文地址:https://www.cnblogs.com/1a-1a/p/5326825.html
Copyright © 2011-2022 走看看