Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 8 Exercise 36, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY. 8.36 (Latin square) A Latin square is an n-by-n array filled with

Chapter 8 Exercise 36, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

8.36 (Latin square) A Latin square is an n-by-n array filled with n different Latin letters, each occurring exactly once in each row and once in each column. Write a program that prompts the user to enter the number n and the array of characters, as shown in the sample output, and checks if the input array is a Latin square. The characters are the first n characters starting from A . Enter number n: 4 Enter 4 rows of letters separated by spaces: A B C D B A D C C D B A D C A B The input array is a Latin square Enter number n: 3 Enter 3 rows of letters separated by spaces: A F D Wrong input: the letters must be from A to C

Outline for the source code

import java.util.Scanner; public class LatinSquares { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter n number: "); int n = input.nextInt(); char[][] m = new char[n][n]; for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[i].length; j++) { m[i][j] = input.next().charAt(0); } } System.out.println(checkLatinSquare(m)); } public static boolean checkLatinSquare(char[][] m) { // first check if grid has valid letters for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[i].length; j++) { //More statements //Do something } } } // check if every row has unique letters for (int i = 0; i < m.length; i++) { if (!isRowValid(m, i)) return false; } // check if every column has unique letters for (int j = 0; j < m[0].length; j++) { if (!isColumnValid(m,j)) return false; } return true; } public static boolean isColumnValid(char[][] m, int column) { //Statements } public static boolean isRowValid(char[][] m, int row) { //Statements } public static void displayMatrix(char[][] m) { //Statements } public static boolean isValidLetter(char ch, int n) { // ch starts off from A, so subtract one from n n--; return (ch >= 'A' && ch <= 'A' + n); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

3. Develop a case study.

Answered: 1 week ago