代码如下……
参数跟返回值你可以自己添加咯!
Scanner qvod = new Scanner(System.in);
String s = qvod.next();
char[] c = new char[s.length()];
boolean b = false;
for (int i = 0; i < c.length; i++) {
c[i]=s.charAt(i);
}
for (int i = 0; i < c.length; i++) {
//防止数组越界操作
if (c.length>i+3) {
if (c[i]==c[i+1]&&c[i]==c[i+2]&&c[i]==c[i+3]) {
b=true;
}
}
}
if (b) {
System.out.println("TRUE");
} else {
System.out.println("FALSE");
}
-------------------------------------分割完结线--------------------------
public static void main(String[] args) {
isConsecutiveFour(new int[]{5,2,3,5});//用户输入的数
}
public static Boolean isConsecutiveFour(int[] values){
int[] n=new int[]{5,2,3,5};///指定的数
if(n.length==values.length){
for(int i=0;i
if(n[i]!=values[i]){
System.out.println("false");
return false;
}
}
System.out.println("true");
return true;
}
return null;
}
最粗暴的做法..用for循环
public boolean isConsecutiveFour(int[] values){
boolean flag = false ;
int i=0 ;
int len = values.length ;
while(!flag&&iif(values[i]==values[i+1]){
if((i+2if((i+3 flag = true ;
}
}
}
i++ ;
}
return flag ;
}