Problem regarding decreasing value in every row

package Section1pattern;

import java.util.Scanner;

public class Pattern27 {

public static void main(String[] args) {
	// TODO Auto-generated method stub

Scanner scn = new Scanner(System.in);
System.out.println(“Enter the number of rows”);
int n = scn.nextInt();
int q = n-1;

int counter = 1;
for(int i = 1 ; i<=n;i++) {
int t = 1;
while(t<=2) {
for(int j =1;j<=q;j++) {
System.out.print("\t");

	}
	if(t!=2) {
		int y=1;
	
		
		for(int r=1;r<=counter;r++) {
			
			System.out.print(y);
			System.out.print("\t");
			y++;
		}
		
		counter=counter+1;
	}
	
		

	t++;
}
System.out.println("\n");
q=q-1;

}
}

}

I am not getting how to decrease the value in every single row. i cant understand how to make that loop.

You don’t need to make a separate loop for this. Inside the loop where you are printing the values for every row, keep a count of the column. So, for every row, till column/2 the value will increase and after that the value will decrease. Use an ‘if-else’ block for this. This has been illustrated in the video as well.
Try altering your code using this logic, and if you not able to, then let me know and I will give more hints.

Thank you so much. I did it and it works fine.:grin:

Glad I could help, if you have no further queries about this question then please mark the doubt as resolved :slight_smile:

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.