What is the problem in my code pls help me

public static void TravelRowWise(Character[][] park, int K, int S, int N, int M) {
boolean flag = true;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {

			if (S < K) {
				flag = false;
				break;
			}
			if (park[i][j] == '.') {
				// . occurs decrease S by 2
				S = S - 2;

			} else if (park[i][j] == '*') {
				S = S + 5;

			} else if (park[i][j] == '#') {

				break;

			}
			if (j != N - 1) {

				S--;

			}
		}
	}
	if (flag) {
		System.out.println("Yes");
		System.out.println(S);
	} else {
		System.out.println("No");
		System.out.println(S);
	}
}

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();
	int M = sc.nextInt();
	int K = sc.nextInt();
	int S = sc.nextInt();
	Character[][] park = new Character[N][M];

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			park[i][j] = sc.next().charAt(0);
		}
	}
	TravelRowWise(park, K, S, N, M);

}

@nigamshubham1998 Just now I have replied with a corrected code, so did you even bother to check it bro? I even added //change comments to it!

@nigamshubham1998
Here it was the corrected code, atleast read the previous threads you open! And if your ans is no then you don’t have to print S.

Hi buddy check the change comments below. no need to put that extra condition n in loop.
If your doubt is clear mark it resolved and rate full.

import java.util.*;
public class Main {
public static void TravelRowWise(Character[][] park, int K, int S, int N, int M) {
boolean flag = true;
for (int i = 0; i < park.length ; i++) { //change 1
for (int j = 0; j < park[i].length; j++) { //change 2

		if (S < K) {
			flag = false;
			break;
		}
		if (park[i][j] == '.') {
			// . occurs decrease S by 2
			S = S - 2;
			
		} else if (park[i][j] == '*') {
			S = S + 5;
			
		} else if (park[i][j] == '#') {

			break;
		}
		// decrease strength from o to n-1 except last col
		if (j != N - 1) {
			S--;
		}
	}
}
if (flag) {
	System.out.println("Yes");
	System.out.println(S);
} else {
	System.out.println("No");
	//System.out.println(S);//change 3
}

}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int N = sc.nextInt();
int M = sc.nextInt();
int K = sc.nextInt();
int S = sc.nextInt();
Character[][] park = new Character[N][M];

for (int i = 0; i < N; i++) {
	for (int j = 0; j < M; j++) {
		park[i][j] = sc.next().charAt(0);
	}
}
TravelRowWise(park, K, S, N, M);

}
}