如何确定一组字符串是否是java中的字方块 [英] How to determine whether a group of strings is a word square in java

查看:90
本文介绍了如何确定一组字符串是否是java中的字方块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我输入像bard,area,rear和dart这样的字符串 - 程序应该显示它是一个单词square



我尝试了什么:



我尝试了charAt()函数,但我无法完全理解该怎么做

if I input strings like bard, area, rear, and dart - the program should show that it is a word square

What I have tried:

I tried the charAt() function but I can't fully understand what to do

推荐答案

将单词复制到字符串数组(正方形的行)中。然后通过连接每个单词的第N个(N = 0到数字-1)字母来迭代单词中的字母数并构建一个新数组(正方形的列)。然后你应该拥有可以形成正方形的所有单词。您现在需要做的就是将每行中的字符串与相应的列字符串进行比较。
Copy the words into an array of strings (the rows of the square). Then iterate the number of letters in a word and build a new array (the columns of the square), by concatenating the Nth (N = 0 to number-1) letters from each word. You should then have all the words that can form the square. All you now need to do is compare the strings in each row with the corresponding string of the columns.


这篇关于如何确定一组字符串是否是java中的字方块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆