「メイン」と「FOR」の2つのクラスがあります。「Main」から、クラス「FOR」のメソッド「display」を呼び出します。「display」は複数の文字列値を取得し、「Main」クラスに返します。ここで、返された値を表示する必要があります。
1 つの値のみが返されます。複数の値が返されるようにするにはどうすればよいですか?
Main.class
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
FOR obj = new FOR();
String str = obj.display();
System.out.print(str);
}
}
授業のために
public class FOR {
int j=5;
String hi="hi";
String display()
{
for(int i=0;i<j;i++)
{
System.out.print(hi);
// If I use this I will get 5 times hi.. but I dont
/// want like this. I have to return hi String 5times to main and I have to display
/// but should not call 5 times display() too,by calling one time, I have to return
/// 5 time a string to Main class
}
return hi;
}
}
望ましい出力は、メソッド「display」から 5 つの値を返すことです。ここでは、HI を 5 回取得する必要があります。