-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvenIndexes.java
34 lines (25 loc) · 940 Bytes
/
EvenIndexes.java
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
import java.util.Scanner;
/** Refer it again
*/public class EvenIndexes {
public static void main(String[] args) {
Scanner take = new Scanner(System.in);
System.out.println("Enter the String:");
String str = take.nextLine();
StringBuilder SBuilder = new StringBuilder();
char[] stringCharacters = str.toCharArray();
for (int i = 0; i < stringCharacters.length; i++) {
char c = stringCharacters[i];
if (i % 2 == 0) {
if (i >= stringCharacters.length) {
c = 1; // this doesn't work
} else if (i < stringCharacters.length) {
if ((i + 2) < stringCharacters.length) {
c = stringCharacters[i + 2];
}
}
}
SBuilder.append(c);
}
System.out.println("Modified string is: " + SBuilder);
}
}