-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMissingChar.java
More file actions
17 lines (15 loc) · 677 Bytes
/
MissingChar.java
File metadata and controls
17 lines (15 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0..str.length()-1 inclusive).
* missingChar("kitten", 1) → "ktten"
* missingChar("kitten", 0) → "itten"
* missingChar("kitten", 4) → "kittn"
*/
public class MissingChar {
//Class for testing and setting dummy values
public static void main( String [] args ) {
//Output tests
System.out.println( missingChar( "Hello World", 5 ) );
}
public static String missingChar( String str, int n ) {
return str.substring( 0, n )+ str.substring( n + 1 );
}
}