⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pyramid.java

📁 斯坦福大学的Java课上的作业
💻 JAVA
字号:
/*
 * File: Pyramid.java
 * Name: 
 * Section Leader: 
 * ------------------
 * This file is the starter file for the Pyramid problem.
 * It includes definitions of the constants that match the
 * sample run in the assignment, but you should make sure
 * that changing these values causes the generated display
 * to change accordingly.
 */

import acm.graphics.*;
import acm.program.*;

public class Pyramid extends GraphicsProgram {

/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

/** Width of each brick in pixels */
	private static final int BRICK_WIDTH = 30;

/** Width of each brick in pixels */
	private static final int BRICK_HEIGHT = 12;

/** Number of bricks in the base of the pyramid */
	private static final int BRICKS_IN_BASE = 14;
	
	public void run() {
		int	ox = getWidth() / 2;
		int x = ox - BRICK_WIDTH * (BRICKS_IN_BASE / 2);
		int y = getHeight();
		int pace = BRICK_WIDTH / 2;

		for(int i = 0; i < BRICKS_IN_BASE; i++){
			for(int j = BRICKS_IN_BASE - i ; j > 0; j--){
				add(new GRect(x + j*BRICK_WIDTH + i * pace, y - i*BRICK_HEIGHT, BRICK_WIDTH, BRICK_HEIGHT));
			//	add(new GRect(x + i*BRICK_WIDTH + j * pace, y - j*BRICK_HEIGHT, BRICK_WIDTH, BRICK_HEIGHT));
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -