Skip to content

Instantly share code, notes, and snippets.

@gebes
Last active June 9, 2020 08:52
Show Gist options
  • Save gebes/9867fdea9815c9c0e2434789a53eede1 to your computer and use it in GitHub Desktop.
Save gebes/9867fdea9815c9c0e2434789a53eede1 to your computer and use it in GitHub Desktop.
Simple solution to the Square Challenge
package uk.microsoft;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int size = new Scanner(System.in).nextInt();
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++)
System.out.print(isOnBorder(i, j, size) ? "*" : " ");
System.out.println();
}
}
private static boolean isOnBorder(int x, int y, int size) {
return (x == 0 || y == 0 || x == size - 1 || y == size - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment