Skip to content

Instantly share code, notes, and snippets.

@PARC6502
Created October 25, 2016 10:30
Show Gist options
  • Save PARC6502/ed913525db4d76a945cb7e40e27381dc to your computer and use it in GitHub Desktop.
Save PARC6502/ed913525db4d76a945cb7e40e27381dc to your computer and use it in GitHub Desktop.
/* Sheet 4 Exercise B
* Written by: Ibrahim El-Serafy (Ibby)
* First written: 18/10/2016
* Last updated: 25/10/2016
*/
import sheffield.*;
public class Exercise4b {
public static void main(String[] args) {
final String SPACE = " ";
final String STAR = "*";
EasyReader keyboard = new EasyReader();
int numberOfLines = keyboard.readInt("Please enter an odd number: ");
int lengthOfLine = (2*numberOfLines)-1;
for (int i=1; i<= numberOfLines; i++) {
int numberOfStars = (2*i)-1;
int numberOfSpaces = lengthOfLine - numberOfStars;
System.out.print(
new String(new char[numberOfSpaces/2]).replace("\0", SPACE));
System.out.print(
new String(new char[numberOfStars]).replace("\0", STAR));
System.out.println(
new String(new char[numberOfSpaces/2]).replace("\0", SPACE));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment