-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
35 lines (28 loc) · 1.1 KB
/
Copy pathMain.java
File metadata and controls
35 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
System.out.print("Enter number of columns: ");
int cols = sc.nextInt();
// Consume the trailing newline left by nextInt before reading full row strings.
sc.nextLine();
char[][] grid = new char[rows][cols];
for (int i = 0; i < rows; i++) {
System.out.print("Enter row " + i + " (e.g., S01): ");
String line = sc.nextLine();
// Copy each character into the grid up to the configured column count.
for (int j = 0; j < cols && j < line.length(); j++) {
grid[i][j] = line.charAt(j);
}
}
PathValidator validator = new PathValidator(grid);
if (validator.pathExists()) {
System.out.println("Path Exists");
} else {
System.out.println("No Path Exists");
}
sc.close();
}
}