KCE_0004 - Editorial

Problem Link:

Patter-01
Inception

Setter : rohinth_076
Tester : rohinth_076
Editorialist: rohinth_076

DIFFICULTY:

Simple

PREREQUISITES:

None

PROBLEM:

Emma is a brilliant student. So all the staff gave works to her. She has many works to do. So she asks you to help to do the following work.

We are given an Integer R Number of Rows. You need to print the Following Pattern.

Input :
6

Output:

******
*    *
*    *
*    *
*    *
******

EXPLANATION:

  • The stars are only printed in
    1 . First row ( i = 1)
    2. First column (j = 1)
    3. Last row (i == r)
    4. Last column ( j == r)
  • So print starts in the above four positions and the remaining are blank space

TIME COMPLEXITY:

O(r*r) for each test case.

SOLUTION:

import java.io.*;
import java.util.*;
class Solution{
	static Scanner fs  = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
	    
	    int r = fs.nextInt();
       for(int i=1;i<=r;i++){
           for(int j=1;j<=r;j++){
               if(i == 1 || j == 1 || i == r || j == r)
                    out.print("*");
               else
                    out.print(" ");
           }
           out.println();
       }
       	out.flush();
		
	}
}

Please comment below if you have any questions, alternate solutions, or suggestions. :grin: