Skip to content

Instantly share code, notes, and snippets.

@muthugit
Created April 15, 2017 20:17
Show Gist options
  • Save muthugit/644592334ad133ac7bbd2aa654f3d2c0 to your computer and use it in GitHub Desktop.
Save muthugit/644592334ad133ac7bbd2aa654f3d2c0 to your computer and use it in GitHub Desktop.
public class Triangle {
public static void main(String[] args) {
String input = "abcdefghijklmnopqrstuvwxyz";
int rowSize = 1, stringPosition = 0;
for (int index = 0; index < (input.toCharArray().length / 2); index++) {
String output = "";
for (int i = 0; i < rowSize; i++) {
output = output + (input.toCharArray()[stringPosition]);
stringPosition++;
}
System.out.println(output);
if (stringPosition >= input.toCharArray().length / 2)
rowSize--;
else
rowSize++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment