-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSayHi.java
More file actions
26 lines (23 loc) · 593 Bytes
/
SayHi.java
File metadata and controls
26 lines (23 loc) · 593 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
/* 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 SayHi {
//Class for testing and setting dummy values
public static void main( String [] args ) {
//Output tests
System.out.println( startHi( "hi there" ) );
}
public static boolean startHi( String str ) {
if( str.length() < 2 ) {
return false;
}
String isHi = str.substring( 0, 2 );
if( isHi.toLowerCase().equals( "hi" ) ) {
return true;
} else {
return false;
}
}
}