-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarInJark.java
50 lines (36 loc) · 1.12 KB
/
StarInJark.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package starinjark;
import java.util.Scanner;
/**
*
* @author daniel
*/
public class StarInJark {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = "Jark";
System.out.print("Enter index: ");
int index = input.nextInt();
// if (index < str.length()) {
// char rpl = str.charAt(index);
// System.out.println(str.replace(rpl, '*'));
// } else {
// System.out.println("Out of bounds");
// System.exit(0);
// }
if (index < str.length()) {
String[] s = new String[str.length()];
char[] chars = new char[str.length()];
str.getChars(0, str.length(), chars, 0);
for (int i = 0; i <= index; i++) {
chars[index] = '*';
}
for (char c : chars) {
System.out.print(c);
}
System.out.println();
} else {
System.out.println("Out of bounds");
System.exit(0);
}
}
}