-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSongPlaylist.java
More file actions
35 lines (31 loc) · 963 Bytes
/
Copy pathSongPlaylist.java
File metadata and controls
35 lines (31 loc) · 963 Bytes
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
import java.util.Scanner;
public class SongPlaylist {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter playlist :");
String str = sc.nextLine();
int n = sc.nextInt();
System.out.println(favCount(str, n));
}
static int favCount(String str, int n) {
int i = 0, j = n;
int maxCount = 0;
while (j <= str.length()) {
int count = 0;
String subStr = str.substring(i, j);
System.out.println(subStr);
for (int k = 0; k < n; k++) {
System.out.println(subStr.charAt(k));
if (subStr.charAt(k) == 'a') {
count++;
}
}
if (count > maxCount) {
maxCount = count;
}
i++;
j++;
}
return maxCount;
}
}