Java输出指定图形--菱形

来源:互联网 发布:零基础学算法百度云 编辑:程序博客网 时间:2024/05/18 01:46
package xiaofei.bank.com;import java.util.Scanner;public class MaiClass {public static void main(String[] args) {Scanner s = new Scanner(System.in);int len = s.nextInt();for (int i = 0; i <= len; i++) {if (i<=(len/2)) {for (int j = 0; j < (len/2)-i; j++) {System.out.print(" ");}for (int j = 0; j <= i; j++) {System.out.print("* ");}System.out.println();}else {for (int j = 0; j < i-(len/2); j++) {System.out.print(" ");}for (int j = 0; j < (2*(len/2))-i+1; j++) {System.out.print("* ");}System.out.println();}}System.out.println("OVER");}}


知识点:

1、循环的嵌套使用

2、读取键盘(Scanner)


0 0