-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRG44_TekrarEdenHarfleriBulun.java
More file actions
39 lines (31 loc) · 1.16 KB
/
Copy pathRG44_TekrarEdenHarfleriBulun.java
File metadata and controls
39 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package Practice_Mentoring;
import java.util.ArrayList;
import java.util.List;
public class RG44_TekrarEdenHarfleriBulun {
public static void main(String[] args) {
/*44----
String içindeki birden fazla geçen karakter sayısını bulan program yazınız.
Mesela "Merhaba" kelimesinde sadece a harfi tekrar ettiği için
bu String için sonuç 1 olacak.
Eğer herhangi tekrar eden bir harf yoksa 0 sayısını döndersin program.
Örnekler:
duplicates("Hello World!")
Çıktı : 2
duplicates("foobar")
Çıktı : 1
duplicates("helicopter")
Çıktı : 1
*/
String str="foobar";
List<String> list=new ArrayList<>();
for (int i = 0; i < str.length(); i++) {
if (str.indexOf(str.substring(i,i+1))!=str.lastIndexOf(str.substring(i,i+1))) { //tekrar edilirse if bodyye gir
if (!list.contains(str.substring(i,i+1))) { //tekrar edilen listimde yoksa ekle
list.add(str.substring(i, i + 1));
}
}
}
System.out.println(list);
System.out.println(list.size());
}
}