이것은 내가 지금 가지고있는 것입니다. 각 줄을 다른 줄에 인쇄하려고합니다 (요구 사항 5 번).배열의 각 요소를 다른 행으로 인쇄하는 방법은 무엇입니까?
공용 클래스 기능 {
public static BufferedReader lifeIsBuff = new BufferedReader(new InputStreamReader(System.in));
public static void run() throws IOException {
FibonacciCalculator();
}
public static void FibonacciCalculator() throws IOException {
//1: Prompt the user for a positive number.
//2: Initialize an array to that size.
//3: Populate indices 0 and 1 with the value of 1.
//4: Using a for loop, populate the remaining spaces in the array with the correct Fibonacci value.
//5: Print each value to the console in their own lines.
//6: This app runs once and closes.
System.out.println("Please enter a positive number: ");
String input = lifeIsBuff.readLine();
int arraySize = Integer.parseInt(input);
long[] nums = new long[arraySize];
nums [0] = 1;
nums [1] = 1;
for (int i = 2; i < nums.length; i++) {
nums [i] = nums [i - 1] + nums [i - 2];
}
System.out.println(Arrays.toString(nums));
}
}
출력은 다음과 같습니다
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]
그러나 나는 다른 라인을해야합니다. 내가 좋아하는 다양한 방법을 시도 :
}
System.out.println(nums);
}
그러나 이것은 단지 문자열 반환 : 나는 다른 다양한 방법을 시도
[[email protected]
을, 그러나 이것은 내가 들어 왔 가장 가까운, 내가 ' ve는 각 요소를 자체 행으로 출력하는 다양한 방법을 찾았지만 코딩을 처음 사용하기 때문에 코드를 이해할 수 없거나 코드 작성 방법을 파악할 수 없었습니다. 어떤 도움을 주시면 감사하겠습니다. 감사합니다.
넣어'에서 System.out.println (nums [I]); '당신의 루프 ('nums [I]'에 할당 후). –
감사합니다. Elliott 나는 그랬다. 그것은 나를 잡아주는 작은 것들입니다. 도와 주셔서 감사합니다. –