zoukankan      html  css  js  c++  java
  • 2017-今日头条笔试题

     1 package com.shb.java;
     2 
     3 import java.util.ArrayList;
     4 import java.util.Arrays;
     5 import java.util.List;
     6 
     7 /**
     8  * 实现将字符串中重复次数打印出来(就是这个意思,原话描述不清了)
     9  * @author shaobn
    10  * @date 2016-9-28
    11  * @package_name com.shb.java
    12  */
    13 public class Demo9 {
    14     public static void main(String[] args) throws Exception {
    15         getMethod("hellohello");
    16     }
    17     /**
    18      * 自己写的方法,将数组转化成集合来做,删一个然后加上一个在他后面
    19      * 觉得方便的是集合的方法,不愿意在数组中操作,过为繁琐。
    20      * @param str
    21      * @date 2016-9-28
    22      * @author shaobn
    23      */
    24     public static void getMethod(String str){
    25         char[] ch = str.toCharArray();
    26         int len = ch.length;
    27         int count = 0;
    28         Character[] characters = new Character[len];
    29         for(int i=0;i<len;i++){
    30             characters[i] = ch[i];
    31         }
    32         List<Character> list = new ArrayList<Character>(Arrays.asList(characters));
    33         System.out.println(list.toString());
    34         int i =0;
    35         while(i<len){
    36             list.add(list.remove(0));
    37             if(list.equals(Arrays.asList(characters))){
    38                 count++;
    39             }
    40             i++;
    41         }
    42         System.out.println(count);
    43     }    
    44     }
  • 相关阅读:
    不要随便用#define 沉沉_
    转载堆和栈的区别 沉沉_
    转载include包含源文件引发的错误 沉沉_
    浅议C和C++中的内存分配 沉沉_
    volatile 的应用 沉沉_
    Debian显示txt乱码
    Debian 64位安装wink
    Debian安装vmware虚拟机
    Debian安装scim中文、日语输入法
    Debian安装chrome
  • 原文地址:https://www.cnblogs.com/assassin666/p/5918063.html
Copyright © 2011-2022 走看看