-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.7.5 Bug Hunter.java
More file actions
39 lines (35 loc) · 1001 Bytes
/
3.7.5 Bug Hunter.java
File metadata and controls
39 lines (35 loc) · 1001 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
public class BugHunter extends ConsoleProgram
{
public void run()
{
String test1 = "Debug";
String test2 = "bugs bunny";
String test3 = "boogie";
String test4 = "baby buggie";
int index1 = findBug(test1);
int index2 = findBug(test2);
int index3 = findBug(test3);
int index4 = findBug(test4);
printBug(test1, index1);
printBug(test2, index2);
printBug(test3, index3);
printBug(test4, index4);
}
// Returns the index of the String "bug" inside the String str
// If str does not contain the String "bug", returns -1
public int findBug(String str)
{
return str.indexOf("bug");
}
public void printBug(String test, int index)
{
if(index != -1)
{
System.out.println(test + " has a bug at index " + index);
}
else
{
System.out.println(test + " has no bugs");
}
}
}