-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWavyText.java
More file actions
30 lines (23 loc) · 807 Bytes
/
Copy pathWavyText.java
File metadata and controls
30 lines (23 loc) · 807 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
29
30
package io.codelex.notes.day10;
public class WavyText {
public static void main(String[] args) {
String text = "Hello World! This text is wavy.";
int amplitude = 2;
char[][] lines = new char[amplitude * 2 + 1][text.length()];
boolean goingDown = true;
int displacement = amplitude;
for (int i = 0; i < text.length(); i++) {
lines[displacement][i] = text.charAt(i);
if (displacement == 0 || displacement == amplitude * 2) {
goingDown = !goingDown;
}
displacement += goingDown ? +1 : -1;
}
for (char[] line : lines) {
for (char c : line) {
System.out.print(c != 0 ? c : " ");
}
System.out.println();
}
}
}