Pattern Printing IV
Description
Given an integerN
, and a pattern. Print the pattern as given in the sample I/O.
Note
: Please check for spaces.
Input
The first and the only line of the input contains the value ofN
.
Constraints
1 <=N
<= 25
Output
Print the pattern as given in the sample test case.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0;i<n;i++){
for (int j=0;j<n;j++){
if (j == 0 || j ==n-1 || i ==0){
if (i ==0 && j==n-1){
System.out.print("*");
}else {
System.out.print("* ");
}
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
No comments:
Post a Comment