Java-字符串习题

[00:01.060]That you make my love
[00:03.520]You make my love come down
[00:05.720](down, down, down, down, down...)
[00:08.530]Love come down on you
[00:11.890]Love come down
[00:15.510](down, down, down, down, down...)
[00:15.830]My love come down on you
[00:31.180]That you make my love
[00:33.430]You make my love come down
[00:36.000]Love come down
[00:37.900]Love come down on you
[00:40.910]You make my love come down
[00:43.200]Love come down
[00:44.970]Love come down on you
[00:47.730](Here) , baby
[00:49.790]Tonight we go touch the sky, baby
[00:51.160]Live the life like we so crazy
[00:52.780]Live the life like we young, baby
[00:54.630]You and me
[00:55.530]We go touch it down
[00:56.430]And can't stand in the way
[00:57.390]'Cause I love full sound
[00:58.480]The true voice
[00:59.180]We go home tonight
[01:00.180]We can head it of here
[01:01.640]The night is the night
[01:02.540]Is nobody as seems would like you (yeah)
[01:05.770]Baby are to sneak tonight? (I need to the life)
[01:09.470]Amazingly it never it think it do (that you know)
[01:12.870]The love just feels all right (haha, if feel so problem)
[01:18.060]You make my love
[01:20.620]You make my love come down
[01:22.820]You make my love come down
[01:24.420]You make my love
[01:28.230]You make my love come down
[01:30.240](down, down, down, down...)
[01:31.710]If you can see my heart you'll know
[01:35.730]You'll know
[01:38.630]That you make my love
[01:41.010]You make my love come down
[01:43.680]Love come down
[01:45.440]Love come down on you
[01:54.000]
[01:58.310]
[01:59.820]
[02:01.300]That you make my love
[02:03.450]You make my love come down
[02:05.960]Love come down
[02:07.710]Love come down on you
[02:10.800]You make my love come down
[02:13.110]Love come down
[02:15.020]Love come down on you
[02:17.790]It's a perfect night, let's enjoy it
[02:18.990]Stop ya baby so let
[02:20.850]Bump it out, don't spoil it
[02:22.650]The worlds and a hang gotta love it
[02:24.760]Everybody all around the world
[02:26.420]Put your hands in the air if you love that girl
[02:28.540]See the one that make the life goodly
[02:30.490]See are we in the beach, which you so goodly
[02:32.100]Is nobody as seems would like you (yeah)
[02:35.660]Baby are to sneak tonight (I need to the life)
[02:39.520]Amazingly it never it think it do (that you know)
[02:43.260]The love just feels all right (haha, if feel so problem)
[02:47.360]You make my love
[02:50.590]You make my love come down
[02:52.440]You make my love come down
[02:54.440]You make my love
[02:57.700]You make my love come down
[03:00.810](down, down, down, down...)

1.求字符串中某个元素出现的次数。

public class Test1 {
	public static void main(String[] args) {
	countString("abbbbbc","a"); //在abbbbbc中查找a
 }
	public static void countString(String str,String s){
	int count=0;
	while(str.indexOf(s)!=-1) {
		str=str.substring(str.indexOf(s)+1, str.length());
		count++;
		}
	System.out.println(count+"个");
	}
}

2.将字符串逆置。

方法一①:利用字符数组

public class Test2 {
  public static char[] reverseString(String str, int start, int end) {
          char[] array = str.toCharArray();  //toCharArray() ,作用:将字符串转换为字符数组。
          while (start <= end) {
              char temp = array[start];
              array[start] = array[end];
              array[end] = temp;
              end--;
              start++;
          }
         return array;
      }
  public static void main(String[] args) {
         String str = "abcde";
         System.out.println("转置之前:" + str);
         char[] array = Test2.reverseString(str, 0,str.length()-1);
         System.out.print("转置之后:");
         for (int i = 0; i < array.length; i++) {
              System.out.print(array[i]);
          }
   }
 }

方法②:利用String的方法

public class Test2 {
	public static void main(String[] args) {
		String str = "hello";
		for (int i = str.length() - 1; i >= 0; i--) {
		    char c = str.charAt(i);	
		    System.out.print(c);
		}
	}
}

个人所做 仅供参考

南国旧梦i

南国旧梦i

出生于苏北小镇 习惯了一个人坐在电脑前 喜欢一个人听着音乐 梦想着一天有一趟说走就走的旅行·······目前过着大学生活,开始了程序人生。

留下你的评论

*评论支持代码高亮<pre class="prettyprint linenums">代码</pre>