다이아몬드 패턴으로 fibonacci 계열을 인쇄 할 사용자 입력 (행 수)을 기반으로합니다. 사용자는 행의 번호를 입력하고 출력은다이아몬드 패턴에서 fibonacci 숫자를 인쇄하는 방법
예상 출력으로 피보나치 시리즈
import java.util.*;
public class HelloWorld {
public static void main(String []args) {
Scanner sc = new Scanner(System.in);
//Taking noOfRows value from the user
System.out.println("Enter no of rows:");
int noOfRows = sc.nextInt();
//Initializing rowCount with 1
int rowCount = 1;
//Implementing the logic
int previous = 0, prevtoprev;
for (int i = noOfRows; i > 0; i--) {
//Printing i*2 spaces at the beginning of each row
for (int j = 1; j <= i*2; j++) {
System.out.print(" ");
}
//Printing j value where j value will be from 1 to rowCount
for (int j = 1; j <= rowCount; j++) {
if (j%2 == 0) {
System.out.print("+");
} else {
System.out.print(j);
}
}
//Printing j value where j value will be from rowCount-1 to 1
for (int j = rowCount-1; j >= 1; j--) {
if (j%2 == 0) {
System.out.print("+");
} else {
System.out.print(rowCount);
}
}
System.out.println();
//Incrementing the rowCount
previous = rowCount;
rowCount++;
}
}
}
을 얻기 출력을 인쇄하는 많은 행을 포함해야한다 : 여기
"(34) "는 다이아몬드를 형성하기 위해 다음 행에"4 "를 배치하고 마지막 행에"1 "을 배치하기 위해"144 "가 분할되고 나머지 자릿수 '44'는 버려집니다. 내가 행 의 수를 기준으로 피보나치 시리즈를 인쇄 할 수 있어요 그러나 여전히 올바른 일이 아니다
부정적 점검을하는 사람들이 거의없는 이유는 무엇입니까? – Girish
예상되는 출력은 무엇입니까? –
질문을 편집하십시오. 코드를 선택하고'{} '버튼을 클릭하여 코드를 올바르게 포맷하십시오. "다이아몬드 형식"이 무엇이고 예상되는 결과가 무엇인지 설명하고 * 질문하십시오 *. – RealSkeptic