Я не знаю, как программировать ... Я работал над этим в Computer Science Classjava.lang.StringIndexOutOfBoundsException: индекс строки из диапазона: 7
Instruction: Use nested loops to print out the square word pattern show below. I'm guessing the error is in the toString method, but I can't spot where.
желаемый результат: (при входе ПЛОЩАДЬ)
SQUARE
Q R
U A
A U
R Q
ERAUQS
код:. импорта статического java.lang.System *;
class BoxWord
{
private String word;
public BoxWord()
{
word="";
}
public BoxWord(String s)
{
setWord(s);
}
public void setWord(String w)
{
word=w;
}
public String toString()
{
String output=word +"\n";
for(int i =0;i<word.length(); i++){
output += word.charAt(i);
for(int j = 2; j<word.length();j++)
output += " ";
output+= word.charAt(word.length()-(i-1))+ "\n";
}
for(int k=0; k<word.length(); k++)
output+= word.charAt(k);
return output+"\n";
}
}
главная:
import static java.lang.System.*;
public class Lab11f
{
public static void main(String args[])
{
BoxWord test = new BoxWord("square");
out.println(test);
}
}
Просьба добавить стопку tracke –
Если входной сигнал 'square', какой должен быть вывод? –
Используйте IDE и отлаживайте программу. Это не так сложно. – Jayan