I’m able to do question 7 pattern but not in the same way as of other patterns. I’ve used the method of columns here instead of nst and nsp.
Can you tell me how to do it using nst and nsp?
Doubt in method of ques 7
@rg361 Here is my Solution for this Pattern :
import java.util.*;
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++){
//printing First star
System.out.print("* ");
//checking if the row is first or last. If it is then we need to print Line of stars otherwise spaces
if(i == n-1 || i == 0){
for(int j = 0; j < n-2 ; j++){
System.out.print("* ");
}
}else{
//iff not we need to print n-2 spaces
for(int j = 0; j < n-2; j++){
System.out.print(" ");
}
}
//printing last star
System.out.print("* ");
System.out.println();
}
}
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.