을 만드는 자바 루프 ...을 위해 나는 다음과 같은 출력을 인쇄 루프 중첩을 쓸 생각 해요 :은 피라미드
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
가 나는 두 가지 방법을 사용하기로되어 있어요.
주 방법은 사용자가 원하는 행 수를 얻는 것으로 가정합니다.
- 는
- 인쇄 행의 수
- 반환 아무것도 피라미드를 행 수 있습니다 가 나는 것을 printPyramid라는 다른 방법을 쓰기로되어 있어요.
지금까지 내가 가진 :
import java.util.Scanner;
public class Pyramid {
//Getting number of rows, calling printPyramid in main method
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//Get user input = number of lines to print in a pyramid
System.out.println("Enter the number of lines to produce: ");
int numLines = input.nextInt();
//call method:
printPyramid();
}//End of main method
//Making a new method...
public static void printPyramid (int numLines) {
int row;
int col;
row = 0;
col = 0;
for (row = 1; row <= numLines; row++){
//print out n-row # of spaces
for (col = 1; col <= numLines-row; col++){
System.out.print(" ");
}
//print out digits = 2*row-1 # of digits printed
for (int dig= 1; dig <= 2*row-1; dig++){
System.out.print(row + " ");
}
System.out.println();
}//end of main for loop
}//end of printPyramid
}//end of class
나는 오류를 얻을 내가 제대로 인쇄 할 얻는 방법을 알아낼 수 없습니다. 나는 그 방법이 엉망이라고 믿는다.
오류를 게시 할 수 있습니까? 당신이 그것에 대해 아무것도 모르는 경우 오류를 수정하기가 아주 어렵습니다. ** 및 **이 숙제입니까? – elyashiv
* 오류가 발생했습니다 ... * 어떤 오류가 있습니까? – Pigueiras
질문을 세분화하여 관련 기능 코드/디버깅 오류가있는 단일 기능/구획을 표시하고 – Ozzy