1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. public class BatchProcessor {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7. List<String[]> data = new ArrayList<>();
  8. while (true) {
  9. String line = scanner.nextLine();
  10. if (line.trim().isEmpty()) {
  11. break; // Exit on empty line
  12. }
  13. String[] values = line.split(","); // Split by comma
  14. if (values.length < 2) {
  15. System.out.println("Invalid input format. Skipping line: " + line);
  16. continue; // Skip invalid lines
  17. }
  18. data.add(values);
  19. }
  20. // Manual override section
  21. System.out.println("\nManual Override:");
  22. System.out.println("Enter row index (0-based) to override values, or 'done':");
  23. String overrideInput = scanner.nextLine();
  24. if ("done".equalsIgnoreCase(overrideInput)) {
  25. System.out.println("Processing data...");
  26. processData(data);
  27. } else {
  28. try {
  29. int index = Integer.parseInt(overrideInput);
  30. if (index >= 0 && index < data.size()) {
  31. System.out.println("Enter new values (comma-separated):");
  32. String[] newValues = scanner.nextLine().split(",");
  33. if (newValues.length == data.get(index).length) {
  34. data.set(index, newValues);
  35. System.out.println("Row " + index + " updated.");
  36. } else {
  37. System.out.println("Invalid number of values for override.");
  38. }
  39. } else {
  40. System.out.println("Invalid row index.");
  41. }
  42. } catch (NumberFormatException e) {
  43. System.out.println("Invalid input format. Please enter a number or 'done'.");
  44. }
  45. }
  46. scanner.close();
  47. }
  48. private static void processData(List<String[]> data) {
  49. for (String[] row : data) {
  50. // Perform processing on each row
  51. System.out.println("Processing: " + String.join(", ", row));
  52. }
  53. }
  54. }

Add your comment