-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartHi
More file actions
28 lines (27 loc) · 858 Bytes
/
startHi
File metadata and controls
28 lines (27 loc) · 858 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
/*Given a string, return true if the string starts with "hi" and false otherwise.
startHi("hi there") → true
startHi("hi") → true
startHi("hello hi") → false
*/
public class startHi {
public static void main(String[] args) {
boolean output=startHi("hi there");
System.out.println(output);
boolean output1=startHi("hi");
System.out.println(output1);
boolean output2=startHi("hello hi");
System.out.println(output2);
boolean output3=startHi("Hi");
System.out.println(output3);
boolean output4=startHi("h");
System.out.println(output4);
}
public static boolean startHi(String str){
if (str.length()<2)
return false;
if (str.substring(0,2).equals("hi"))
return true;
else
return false;
}
}