정말 프로그래밍하는 방법을 모른다 ... 나는 컴퓨터 과학 교실java.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);
}
}
친절하게 스택 추적을 추가합니다. –
입력이'square'이면 출력은 무엇입니까? –
IDE를 사용하고 프로그램을 디버깅하십시오. 그리 어렵지 않습니다. – Jayan