-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerWarmup.java
More file actions
41 lines (33 loc) · 765 Bytes
/
HackerWarmup.java
File metadata and controls
41 lines (33 loc) · 765 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
36
37
38
39
40
41
package poorvatutorial1;
public class HackerWarmup {
public static void main(String[] args) {
String s = "bba";
int n = 10;
int count = 0;
int l = s.length();
for(int i = 0; i<l; i++)
{
if(s.charAt(i) == 'a')
{
count++;
}
}
System.out.println(count);
int occurances = n / l;
int remainder = n % l;
int total = occurances * count;
if(remainder > 0)
{
String c = s.substring(0,remainder) ;
int length = c.length();
for(int j = 0; j <length ; j++)
{
if(c.charAt(j) == 'a')
{
total++;
}
}
}
System.out.println(total);
}
}