永发信息网

Java里面判断array中的一个string内有没有重复的字母

答案:3  悬赏:50  手机版
解决时间 2021-02-24 11:34
  • 提问者网友:聂風
  • 2021-02-23 19:15
比如一个Array = ACTG TGA TTGA TGGGGAA TGAC
找出字组如TTGA中有没有重复的字母如TT然后返还array里面有多少个有重复字母的
例子里面就有两个,TTGA 和TGGGGAA如果一个里面有两个字母都重复也只记1

求复制党别来,,,百度上的我都看过了。。
最佳答案
  • 五星知识达人网友:痴妹与他
  • 2021-02-23 19:23
你直接循环遍历array,针对array中的每个元素,判断该元素是否有重复字母就可以了。
全部回答
  • 1楼网友:持酒劝斜阳
  • 2021-02-23 21:03
int length =20; string[] strs = new string[length]; int index = 0; while(true){ scanner scan = new scanner(system.in); string store = scan.nextline(); if(store.equals("history"){ for(int i=0;i<strs.length;i++){ system.out.println(strs[i]); } }else if(store.startwiths("find")){ int num=0; try{ num=integer.parse(store.substring("find".length).trim()); num=math.max(0,num); }catch(numberformatexception e){ } system.out.println(num); }else{ if(index>=length){ length += length; strs = arrays.copyof(strs, length); strs[index]=store; index++; } } }
  • 2楼网友:长青诗
  • 2021-02-23 19:44
public class Yugi{     public static int joey(String[] array){         int count = 0;         for(int i = 0; i < array.length; i++){             String ai = array[i];             String tmp = "|" + ai + "|";             for(int j = 0; j < ai.length(); j++){                 String aij = ai.charAt(j) + "";                 if(tmp.split(aij).length - 1 > 1){                     count++;                     break;                 }             }         }         return count;     }     public static void main(String[] args){         String[] array = {"ACTG","TGA","TTGA","TGGGGAA","TGAC"};         System.out.println(joey(array));     } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯