Though I have written code for pattern 7 I don’t know is it’s an efficient one , can you please check?
Pattern 7 Doubt
Post ya code here bro!
package pattern_practice_questions;
import java.util.Scanner;
public class Pattern7 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int rows = 1;
int nst;
int nsp;
while (rows <= n) {
//work
if (rows == 1 || rows == n) {
nst = n;
nsp = 0;
int cst = 1;
while (cst <= nst) {
System.out.print("*");
cst++;
}
} else {
nsp = n-2;
System.out.print("*");
int space = 1;
while (space <= nsp) {
System.out.print(" ");
space++;
}
System.out.print("*");
}
System.out.println();
rows++;
}
}
}
can you please review it
@bhavik911 bro you have done a good job, basically don’t think much about complexity just practice patterns so that you can be good with loop. You will get many questions ahead in which you will play with efficiency.
Good job buddy!
okay, that sounds good
thanks