day3

JavaScript 编程题

查找「sdddrtkjsfkkkasjdddj」字符串中,出现次数最多的字符和次数。

<!DOCTYPE html>

<html>

        <head>

                 <meta charset="UTF-8">

                 <title></title>

        </head>

        <body>

        </body>

        <script>

                 var str = "sdddrtkjsfkkkasjdddj";

                 // 使用对象记录字符出现的次数,键为各个字符,值为字符出现的次数

                 var obj = {};

                 for(var i = 0; i < str.length; i++) {

                         //获得字符

                         var char = str.charAt(i);

                         //若对象已有该字符属性,值加1

                         if(obj[char]) {

                                  obj[char]++;

                                 

                         }else {

                                  //第一次出现该字符,值记为1

                                  obj[char]= 1;

                         }

                 }

                 //记录出现最多次数

                 var max = 0;

                 for(var key in obj) {

                         if(obj[key] >= max) {

                                  max= obj[key];

                         }

                 }

                 //打印

                 for(var key in obj) {

                         if(obj[key] == max) {

                                  console.log("出现次数最多的字符:" + key);

                                  console.log("出现次数:" + obj[key]);

                         }

                 }

        </script>

</html>

 

 

 

DROP TABLE IF EXISTS team;

CREATE TABLE team(

       IDINT(255),

       NameCHAR(255)

)ENGINE=INNODB DEFAULT CHARSET=utf8;

-- 要求:执行一个删除语句,当 Name 列上有相同时,只保留 ID 这列上值小的例如:删除后的结果应如下:

-- SELECT ID,Name FROM team GROUP BY Name ;

INSERT INTO team VALUES ('1','a');

INSERT INTO team VALUES ('2','b');

INSERT INTO team VALUES ('3','b');

INSERT INTO team VALUES ('4','a');

INSERT INTO team VALUES ('5','c');

INSERT INTO team VALUES ('6','c');

 

 

DELETE

FROM team

WHERE id NOT IN

(SELECT a.id

FROM

(SELECT MIN(id) AS id

FROM team

GROUP BY name ) a)

 

package Daily_practice;

/**

 * 判断 101-200 之间有多少个素数,并输出所有素数。

 * @author pc

 *

 */

publicclass Day3 {

    publicstaticvoid main(String[] args) {

        intcount = 0;

 

        for (inti = 101; i <= 200; i++) {

            intj;

            for (j = 2; j < ij++) {

                // 如果j能被i整除在跳出循环

                if (i % j == 0) {

                   break;

                }

            }

            // 判断循环是否提前跳出,如果j<i说明在2~j之间,i有可整除的数

            if (j >= i) {

                count++;

                System.out.print(i + "\t");

                // 换行,用count计数,每五个数换行

                if (count % 5 == 0) {

                   System.out.print("\n");

                }

            }

        }

    }

   

}

阅读更多
想对作者说点什么?
相关热词

博主推荐

换一批

没有更多推荐了,返回首页