سلام میخوام کاراکترهایی که سه بار پشت سر هم تکرار شده رو پیدا کنم
Printable View
سلام میخوام کاراکترهایی که سه بار پشت سر هم تکرار شده رو پیدا کنم
نمیتونید از regex استفاده کنید؟
اگر میتونید، عبارت regex برای این کار اینه:([A-Za-z])\1\1
متاسفانه نمیتونم استفاده کنم
Scanner scn = new Scanner(System.in)System.out.print("enter text :")
String text = scn.next
int counter = 0
for (int i = 0; i < (text.length()-1); i++) {
int j = i + 1
int k = i+2
if (text.charAt(i) == text.charAt(j) && text.charAt(j) == text.charAt(k))
counter += 1
}
System.out.print(counter)
کدی که خودم نوشتم؟؟؟
Scanner scn = new Scanner(System.in)System.out.print("enter text :");
String text = scn.next;
int counter = 0;
for (int i = 0; i < text.length() - 2; i++)
{
if (text.charAt(i) == text.charAt(i + 1) &&
text.charAt(i) == text.charAt(i + 2))
counter += 1
}
System.out.print(counter);
ممنونم....درست شد