1 javaCopyimport java.util.*;
2import java.lang.*;
3import java.io.*;
4
5public class Example1 {
6 public static void main(String[] args) {
7 String str = "Character";
8 System.out.println(str.contains("h"));
9 System.out.println(str.contains("Char"));
10 System.out.println(str.contains("ac"));
11 System.out.println(str.contains("v"));
12 System.out.println(str.contains("vl"));
13 }
14}
15
1 /*
2 This method returns true if the given string contains
3 the char n. It is necessary due to the
4 obsolescence of some compilers, which requires us
5 to write our own contains method.
6 */
7 public static boolean contains_char (String main, char secondary)
8 {
9 boolean contains_result = false;
10 for (int i = 0 ; i < input.length () ; i++)
11 {
12 if (input.charAt (i) == secondary)
13 {
14 contains_result = true;
15 break;
16 }
17 }
18 return contains_result;
19 }
20
21/*
22for two chars:
23*/
24public static boolean contains_dualchar (String main, String secondary)
25 {
26 boolean contains_result = false;
27 for (int i = 0 ; i < input.length () ; i++)
28 {
29 if (input.charAt (i) == secondary.charAt (0))
30 {
31 if (input.charAt (i + 1) == secondary.charAt (1))
32 {
33 contains_result = true;
34 break;
35 }
36 }
37 }
38 return contains_result;
39 }
40