13 个解决方案
#1
package com;
public class Test
{
public static void main(String args[]){
String s="sss";
String s1=s.substring(0, 1);
String s2=s.substring(1, 2);
String s3=s.substring(2, 3);
String s4=s.substring(1, 3);
System.out.println(s1.equals(s2));
System.out.println(s2.equals(s3));
System.out.println(s3.equals(s4));
}
}
public class Test
{
public static void main(String args[]){
String s="sss";
String s1=s.substring(0, 1);
String s2=s.substring(1, 2);
String s3=s.substring(2, 3);
String s4=s.substring(1, 3);
System.out.println(s1.equals(s2));
System.out.println(s2.equals(s3));
System.out.println(s3.equals(s4));
}
}
#2
public boolean allEqual(String str) {
for (int i=1; i<str.length(); i++)
if (str.charAt(i)!=str.charAt(0)) return false;
return true;
}
#3
String str = "J100-J100+100 ";
int cnt=0,start = 0;
while(start!=str.length()){
int i = str.indexOf( str.substring(0, 1),start);
if(i!=-1)
{
cnt ++;
start = i+1;
}
else
break;
}
System.out.println(cnt);
}
统计出首字母在字符串出现的次数 然后和字符串的length 比较是否相等
#4
String 类型 substring结果还是String 那就直接用 str1.equals(str2)比较
#5
没明白您的意思,如果要比较两字符串,直接用str0.equals(str)就能解决了,当然最好trim()下
#6
其实我是想实现从String srcText = "vcxz7bb82epcccojfdkospeeee089y23hfhdisay098fg6780389p2uh32aaaaiuyfdi0000osyauiy";中找出有连续出现的字符串的个数
#7
简单的正则
str = substring(i,j);
int len = str.length();
System.out.println(str.matches(""+str.charAt(0)+"{"+len +"}"));
#8
++
不会的话用循环遍历,好比说你要找"aaaa"重复出现的个数,就按"aaaa"的长度分隔成n-4+1个str(n为str的长度),然后循环遍历
#9
#10
char[] cs=s.toCharArray();
boolean b=false;
char c=cs[0];
int n=0;
for(int i=0,l=cs.length;i<l;i++){
if(cs[i]!=c){
c=cs[i];
if(b){
b=false;
System.out.println();
}
continue;
}
System.out.print(c);
if(b){
continue;
}
System.out.print(c);
if(!b){
b=true;
n++;
}
}
System.out.println(n);
#11
上面有错
char[] cs=s.toCharArray();
boolean b=false;
char c=cs[0];
int n=0;
for(int i=1,l=cs.length;i<l;i++){
if(cs[i]!=c){
c=cs[i];
if(b){
b=false;
System.out.println();
}
continue;
}
System.out.print(c);
if(b){
continue;
}
System.out.print(c);
b=true;
n++;
}
System.out.println(n);
#12
String str = "vcxz7bb82epcccojfdkospeeee089y23hfhdisay098fg6780389p2uh32aaaaiuyfdi0000osyauiy";
Map<Character,Object> map = new HashMap<Character,Object>();
Set<Character> set = new HashSet<Character>();
char[] ch = str.toCharArray();
List<Integer> l = null;
for(int i=0;i<ch.length;i++){
if(map.containsKey(ch[i])){
Object o = map.get(ch[i]);
if(i == (Integer.parseInt(o+"")+1)){
set.add(ch[i]);
}
map.put(ch[i],i);
}else{
map.put(ch[i],i);
}
}
Iterator it = set.iterator();
System.out.print("出现重复字符串的字符为:");
while(it.hasNext()){
System.out.print(it.next());
System.out.print(" ");
}
#13
学习了。
#1
package com;
public class Test
{
public static void main(String args[]){
String s="sss";
String s1=s.substring(0, 1);
String s2=s.substring(1, 2);
String s3=s.substring(2, 3);
String s4=s.substring(1, 3);
System.out.println(s1.equals(s2));
System.out.println(s2.equals(s3));
System.out.println(s3.equals(s4));
}
}
public class Test
{
public static void main(String args[]){
String s="sss";
String s1=s.substring(0, 1);
String s2=s.substring(1, 2);
String s3=s.substring(2, 3);
String s4=s.substring(1, 3);
System.out.println(s1.equals(s2));
System.out.println(s2.equals(s3));
System.out.println(s3.equals(s4));
}
}
#2
public boolean allEqual(String str) {
for (int i=1; i<str.length(); i++)
if (str.charAt(i)!=str.charAt(0)) return false;
return true;
}
#3
String str = "J100-J100+100 ";
int cnt=0,start = 0;
while(start!=str.length()){
int i = str.indexOf( str.substring(0, 1),start);
if(i!=-1)
{
cnt ++;
start = i+1;
}
else
break;
}
System.out.println(cnt);
}
统计出首字母在字符串出现的次数 然后和字符串的length 比较是否相等
#4
String 类型 substring结果还是String 那就直接用 str1.equals(str2)比较
#5
没明白您的意思,如果要比较两字符串,直接用str0.equals(str)就能解决了,当然最好trim()下
#6
其实我是想实现从String srcText = "vcxz7bb82epcccojfdkospeeee089y23hfhdisay098fg6780389p2uh32aaaaiuyfdi0000osyauiy";中找出有连续出现的字符串的个数
#7
简单的正则
str = substring(i,j);
int len = str.length();
System.out.println(str.matches(""+str.charAt(0)+"{"+len +"}"));
#8
++
不会的话用循环遍历,好比说你要找"aaaa"重复出现的个数,就按"aaaa"的长度分隔成n-4+1个str(n为str的长度),然后循环遍历
#9
#10
char[] cs=s.toCharArray();
boolean b=false;
char c=cs[0];
int n=0;
for(int i=0,l=cs.length;i<l;i++){
if(cs[i]!=c){
c=cs[i];
if(b){
b=false;
System.out.println();
}
continue;
}
System.out.print(c);
if(b){
continue;
}
System.out.print(c);
if(!b){
b=true;
n++;
}
}
System.out.println(n);
#11
上面有错
char[] cs=s.toCharArray();
boolean b=false;
char c=cs[0];
int n=0;
for(int i=1,l=cs.length;i<l;i++){
if(cs[i]!=c){
c=cs[i];
if(b){
b=false;
System.out.println();
}
continue;
}
System.out.print(c);
if(b){
continue;
}
System.out.print(c);
b=true;
n++;
}
System.out.println(n);
#12
String str = "vcxz7bb82epcccojfdkospeeee089y23hfhdisay098fg6780389p2uh32aaaaiuyfdi0000osyauiy";
Map<Character,Object> map = new HashMap<Character,Object>();
Set<Character> set = new HashSet<Character>();
char[] ch = str.toCharArray();
List<Integer> l = null;
for(int i=0;i<ch.length;i++){
if(map.containsKey(ch[i])){
Object o = map.get(ch[i]);
if(i == (Integer.parseInt(o+"")+1)){
set.add(ch[i]);
}
map.put(ch[i],i);
}else{
map.put(ch[i],i);
}
}
Iterator it = set.iterator();
System.out.print("出现重复字符串的字符为:");
while(it.hasNext()){
System.out.print(it.next());
System.out.print(" ");
}
#13
学习了。