import java.util.*; public class p8 { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("Enter How many rows you want?"); int n=s.nextInt(); for(int i=1; i<=n; i++) { for(int j=1; j<=n-i;j++) { System.out.print(" "); } for(int j=1; j<=2*i-1;j++) { if(i%2==0 && (j==1||j==(i*2-1))) System.out.print("+"); else System.out.print("*"); } System.out.println(); } } } OUTPUT * +*+ ***** +*****+ ********* +*********+ ************* +*************+
import java.util.*; public class p9 { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("Enter How many rows you want?"); int n=s.nextInt(); for(int i=n; i>0; i--) { for(int j=1; j <=n-i;j++) { System.out.print(" "); } for(int j=1; j <=2*i-1;j++) { if(i%2==0&&(j==1||j==(i*2-1))) System.out.print("+"); else System.out.print("*"); } System.out.println(); } } } OUTPUT ************* +*********+ ********* +*****+ ***** +*+ *
No comments:
Post a Comment
If you have any doubts, please let me know