package compute;
public class ComputeDemo {
public static void main(String[] args) {
// Rectangle(10, 10);
// rTriangle(10, 10);
// rTriangle2(10, 10);
// rTriangle3(10, 10);
// rTriangle4(10, 10);
triangle(5, 10);
triangle1(5, 10);
}
/**
等腰三角形 /\
*/
private static void triangle1(int height,int width) {
for (int i = 0; i < height; i++) {
for (int j = width; j >0; j--) {
if (j>=(width/2-i)&&j<=(width/2+i)) {
System.out.print('.');
}else {
System.out.print(' ');
}
}
System.out.println();
}
}
/**
等腰三角形 \/
*/
private static void triangle(int height,int width) {
for (int i = 0; i < height; i++) {
for(int j=0;j<width;j++) {
if (j>i&&j<(width-i)) {
System.out.print('.');
}else {
System.out.print(' ');
}
}
System.out.println();
}
}
/**
直角三角形 /|
*/
private static void rTriangle4(int height,int width) {
for (int i = 0; i < height; i++) {
for (int j = width; j>0; j--) {
if (i<(j-1)) {
System.out.print(' ');
}else {
System.out.print('.');
}
}
System.out.println();
}
}
/**
直角三角形 \|
*/
private static void rTriangle3(int height,int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (j<i) {
System.out.print(' ');
}else {
System.out.print(".");
}
}
System.out.println();
}
}
/**
方形
*/
private static void Rectangle(int height,int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
System.out.print(".");
}
System.out.println();
}
}
/**
直角三角形 |\
*/
private static void rTriangle(int height,int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (j<=i) {
System.out.print(".");
}
}
System.out.println();
}
}
/**
* 直角三角形 |/
*/
private static void rTriangle2(int height,int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (j>=i) {
System.out.print(".");
}
}
System.out.println();
}
}
}
算法—for循环应用
于 2022-01-22 20:09:23 首次发布