私が現在取り組んでいるラボでは、これが助けになります。
output = ""
output += word
loop i that runs
{
output += word.charAt(i)
loop j
{
output += " "
}
output += word.charAt( ______ )+ "\n"
}
StringBuffer sb = new StringBuffer(word);
output += word backwards
これが私のコードです。
import static java.lang.System.*;
class BoxWord
{
private String word;
public BoxWord()
{
word="";
}
public BoxWord(String s)
{
word = s;
}
public void setWord(String w)
{
word = w;
}
public String toString()
{
String output="";
output += word + "\n";
for(int i =1; i<word.length(); i++)
{
output += word.charAt(i);
for(int j =i+1; j<word.length()-i; j++)
{
output += " ";
}
output += word.charAt((word.length()-i)) + "\n";
}
StringBuffer sb = new StringBuffer(word);
output += sb;
return output+"\n";
}
}
相互参照用のランナー クラスは次のとおりです。
import static java.lang.System.*;
import java.util.Scanner;
public class Lab11f
{
public static void main( String args[] )
{
Scanner keyboard = new Scanner(System.in);
String choice="";
do{
out.print("Enter the word for the box : ");
String value = keyboard.next();
//instantiate a BoxWord object
BoxWord bw = new BoxWord(value );
//call the toString method to print the triangle
System.out.println( bw );
System.out.print("Do you want to enter more data? ");
choice=keyboard.next();
}while(choice.equals("Y")||choice.equals("y"));
}
}
現在、次のように出力しています。
四角
え
あなたは
ああ
ル
式
四角
次のようにする必要がある場合:
四角
Q>>>>R
う>>>>あ
あ>>>>う
か>>>>か
ERAUQS (">" は空白を表し、最後の列は整列する必要があります)
ラボシートの Google ドキュメント バージョンへのリンクは次のとおりです: https://docs.google.com/open?id=0B_ifaCiEZgtcVTAtT2t0ajRPLUE
更新:
わかりました、それはほとんどの部分で機能しています。私は今これを取得しています:
四角
q>>>>へ
u>>>>r
あ>>>>あ
r>>>>u
へ>>>>q
四角
更新#2 今、私の結果は次のようになります:
四角
q>>>>へ
u>>>>r
あ>>>>あ
r>>>>u
えろく