加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

测试3---将字符串压缩算法

发布时间:2020-12-15 08:23:51 所属栏目:Java 来源:网络整理
导读:1 package com.review; 2 3 import java.util.Scanner; 4 5 /** 6 * @program: com.review 7 * @description: 8 * @author : Mr.Lin 9 * @create: 2019年8月13日 10 * */ 11 public class Compress03 { 12 static Scanner sc= new Scanner(System.in); 13 pu

 1 package com.review;
 2 
 3 import java.util.Scanner;
 4 
 5 /**
 6  * @program: com.review
 7  * @description:
 8  * @author: Mr.Lin
 9  * @create: 2019年8月13日
10  **/
11 public class Compress03 {
12     static Scanner sc= new Scanner(System.in);
13     public static void main(String[] args) {
14         System.out.println("输入:");
15         String cluster = sc.next();
16         
17         String s1 = cluster + " ";
18         String s3 = "";
19         
20         int index;
21         do {
22             index = 0;
23             for(int i=0;i<s1.length();i++) {
24                 if(s1.charAt(i)!=s1.charAt(i+1)) {
25                     index = i+1;
26                     break;
27                 }
28             }
29             String s2 = s1.substring(0,index);
30             s3 += s2.charAt(0) + "" + ((s2.length()-1) == 0 ? "" : s2.length());
31             s1 = s1.substring(index,s1.length());
32         }while(s1.length()>1);
33         System.out.println("输出:n"+s3);
34     } 
35     
36 }
View Code

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读