JAVA
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
/* Solution for challenge: https://www.sololearn.com/Discuss/633313/friday-challenge-write-a-code-that-gets-as-input-a-positive-number-n-1-and-prints-a-n-x-n-clockwise
Objective:
1. get user input / matrix size (int matrixSize);
2. print CLOCKWISE-SPIRAL-SQUARE (matrixSize * matrixSize)
/* Changes:
1. Alignment of output corrected;
2. In order to make the code more readable:
- more comments added;
- variable names changed;
- other small changes;
*/
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
// Get user input
int matrixSize = 0;
System.out.println("PLS enter the matrix size:");
Scanner sc=new Scanner(System.in);
if(sc.hasNextInt()) {
matrixSize=sc.nextInt();
sc.close();
if(matrixSize<2){ // Inputed int doesn't result with an matrix
System.out.println("Ooo come on! What kind of a matrix would that be?! :P\nNext time give me a higher integer. Bye!");
System.exit(-1);
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run