Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must solve USING RECURSIVE METHOD. STARTER CODE BELOW. import java.util.*; public class AtoY { public static void main(String[] args) { Scanner sc = new Scanner(System.in);

image text in transcribedimage text in transcribed

Must solve USING RECURSIVE METHOD.

STARTER CODE BELOW.

import java.util.*;

public class AtoY {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in); char[][] tbl = new char[5][5]; int row = -1, col = -1; String inp; for (int i = 0; i

if(solve(tbl, row, col, 'a')) printTable(tbl); }

public static boolean solve(char[][] t, int row, int col, char c) { // You might use a method signature like this for a recursive // solution. }

public static void printTable(char[][] t) { for (int i = 0; i CS 114, Spring 2020, Prof. Calvin Problem set #1 Due: Wed. January 29, 1:00 pm. Reading/veiwing: Chapter 2 (recursion). For this and all assignments, follow the input/output and naming specifications precisely. In particular, for your final submission your program should not print prompts for input or add text such as "The answer is:", unless the assignment asks you to do so. To receive credit for a problem that asks for a recursive solution, you must use recursion. Programming: You are given a five-by-five array of cells, some of which contain letters and the others are empty. You need to fill the empty squares with letters so that there is a path moving only horizontally or vertically not diagonally) at each step that visits all cells with consecutive letters. The letters are lower case 'a' through 'y', and 'a' is present in one of the starting cells. For example, a solution to gfled uta g Another way to describe the correct output is that if you place the cursor over the 'a', then using only the up, down, left, and right arrows you can move the cursor over the letters 'a' through 'y' in order. Write a program that uses recursion to solve this problem. The input consists of five lines, each containing a string of five lower case letters from 'a' to 'z' with no spaces. An 'a' appears exactly once in the five lines. A 'z' indicates an empty cell. The output is five lines, each containing five characters (without spaces), and the five lines together contain each of the letters 'a' through 'y' according to the rules given above. For example, if the input is Zzzzm zzzzz zzzz zzzaz zzzzu then a correct output is ijklm hgpon efors dcbat yxwvu If no solution exists, your program should reproduce the input. If more than one solution exists, print out just one. Your program should terminate in under a minute for any input. Name your program AtoY and upload it to Vocareum. CS 114, Spring 2020, Prof. Calvin Problem set #1 Due: Wed. January 29, 1:00 pm. Reading/veiwing: Chapter 2 (recursion). For this and all assignments, follow the input/output and naming specifications precisely. In particular, for your final submission your program should not print prompts for input or add text such as "The answer is:", unless the assignment asks you to do so. To receive credit for a problem that asks for a recursive solution, you must use recursion. Programming: You are given a five-by-five array of cells, some of which contain letters and the others are empty. You need to fill the empty squares with letters so that there is a path moving only horizontally or vertically not diagonally) at each step that visits all cells with consecutive letters. The letters are lower case 'a' through 'y', and 'a' is present in one of the starting cells. For example, a solution to gfled uta g Another way to describe the correct output is that if you place the cursor over the 'a', then using only the up, down, left, and right arrows you can move the cursor over the letters 'a' through 'y' in order. Write a program that uses recursion to solve this problem. The input consists of five lines, each containing a string of five lower case letters from 'a' to 'z' with no spaces. An 'a' appears exactly once in the five lines. A 'z' indicates an empty cell. The output is five lines, each containing five characters (without spaces), and the five lines together contain each of the letters 'a' through 'y' according to the rules given above. For example, if the input is Zzzzm zzzzz zzzz zzzaz zzzzu then a correct output is ijklm hgpon efors dcbat yxwvu If no solution exists, your program should reproduce the input. If more than one solution exists, print out just one. Your program should terminate in under a minute for any input. Name your program AtoY and upload it to Vocareum

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions