Practice Pattern28

package PracticePattern;

import java.util.Scanner;

public class PracticePattern33 {

public static void main(String[] args) {

	System.out.println("practiceParttern 33");

	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();

	int rows = 1;
	int nsp = n - 1;
	int nst = 1;
	int val = 0;

	while (rows <= n) {
		// for space
		for (int csp = 1; csp <= nsp; csp++) {
			System.out.print(" ");
		}

		// for work
		int var = rows;
		for (int cst = 1; cst <= nst; cst++) {

			if (cst > 1) {
				System.out.print(rows - rows);
			}

			else {

				System.out.print(var);

			}
		}

		// preparation
		System.out.println();
		nsp--;
		nst = nst + 2;

		rows++;
	}

}

}

Its Practice pattern 29

Hey @Nitya_Somani
just a change inside for loop
for (int cst = 1; cst <= nst; cst++) {

if (cst > 1 && cst < nst) {
System.out.print(rows - rows);
}

			else {

				System.out.print(var);

			}

correct code:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

	System.out.println("practiceParttern 33");

	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();

	int rows = 1;
	int nsp = n - 1;
	int nst = 1;
	int val = 0;

	while (rows <= n) {
		// for space
		for (int csp = 1; csp <= nsp; csp++) {
			System.out.print(" ");
		}

		// for work
		int var = rows;
		for (int cst = 1; cst <= nst; cst++) {

if (cst > 1 && cst < nst) {
System.out.print(rows - rows);
}

			else {

				System.out.print(var);

			}
		}

		// preparation
		System.out.println();
		nsp--;
		nst = nst + 2;

		rows++;
	}

}

}

1 Like