public class ques8 {
public static void main(String[]args){
int n=5;
for(int i=1;i<=n;i++){
//spaces
/*int spaces=0;
for(int j=1;j<=spaces;j++){
System.out.print(" "+"\t");
spaces++;
}*/
//stars(second diagonal)
for(int j=1;j<=i;j++){
if(i==j){
System.out.print("*"+"\t");
}
else{
System.out.print(" "+"\t");
}
}
//star(First diagona)
for(int j=1;j<=n;j++){
if(i+j==6){
System.out.print("*"+"\t");
}
else{
System.out.print(" "+"\t");
}
}
System.out.println();
}
}
}
my output is coming like this:
-
* * * * * * * * *
PS C:\Users\adity\OneDrive\Desktop\Coding blocks\Pr
for the second diagonal i see the logic like:
i+j=6
but i am not getting the correct pattern