关闭

java 打印各种 图形

6304人阅读 评论(0) 收藏 举报
分类:
package ch09;

import java.util.Scanner;

public class Test03
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		System.out.println("请输入行数");
		int rows=input.nextInt();
		for (int i = 0; i < rows; i++)
		{
			for (int j = 0; j <= i; j++)
			{
				System.out.print("* ");
			}
			System.out.println();
		}
		System.out.println("倒过来的三角");
		for (int i = rows-1; i >=0; i--)
		{
			for (int j = 0; j <= i; j++)
			{
				System.out.print("* ");
			}
			System.out.println();
		}
		
	}
}
请输入行数
5
* 
* * 
* * * 
* * * * 
* * * * * 
倒过来的三角
* * * * * 
* * * * 
* * * 
* * 
* 

package ch09;

import java.util.Scanner;



public class Test04
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		System.out.println("请输入行数");
		int row=input.nextInt();
		
		for (int i = 1; i <=row; i++)
		{
			for (int j = 0; j < row-i; j++)
			{
				System.out.print(" ");
			}
			for (int j = 0; j < 2*i-1; j++)
			{
				System.out.print("*");
			}
			System.out.println();
		}
		 
		
	}
}
请输入行数
10
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************

package ch09;

import java.util.Scanner;

public class Test05
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		int row = 0;
		System.out.println("请输入行数");
		row = input.nextInt();
		 while (row%2==0){
			 System.out.println("请输入奇数");
			 row=input.nextInt();
		 }

		for (int i = 1; i <= row; i++)
		{
			for (int j = 0; j < row - i; j++)
			{
				System.out.print(" ");
			}
			for (int j = 0; j < 2 * i - 1; j++)
			{
				System.out.print("*");
			}
			System.out.println();
		}
		for (int i = row-1; i >=0; i--)
		{
			for (int j = 0; j < row - i; j++)
			{
				System.out.print(" ");
			}
			for (int j =2 * i - 1;j>0 ; j--)
			{
				System.out.print("*");
			}
			System.out.println();
		}


	}
}

请输入行数
7
      *
     ***
    *****
   *******
  *********
 ***********
*************
 ***********
  *********
   *******
    *****
     ***
      *
       

package ch09;

import java.util.Scanner;

public class Test06
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		int count = 0;
		System.out.println("请输入边长");
		count=input.nextInt();
		// 控制行数
		for (int i = 0; i < count; i++) {
			if (i == 0 || i == count - 1) {
				// 数组第一个行和最后一行的边
				for (int j = 0; j < count; j++) {
					System.out.print("* ");
				}
			} else {
				// 左边的边
				System.out.print("*");
				// 输出空格
				for (int j = 0; j < count - 2; j++) {
					System.out.print("  ");
				}
				// 右边的边
				System.out.print(" *");
			}
			// 换行
			System.out.println();
		}
		
	}
}
请输入边长
10
* * * * * * * * * * 
*                 *
*                 *
*                 *
*                 *
*                 *
*                 *
*                 *
*                 *
* * * * * * * * * * 

package ch09;public class Test02{public static void main(String[] args){for (int i = 0; i < 13; i++){for (int j = 0; j <= i; j++){System.out.print("* ");}System.out.println();}}}* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


   
2
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:59745次
    • 积分:1225
    • 等级:
    • 排名:千里之外
    • 原创:57篇
    • 转载:1篇
    • 译文:0篇
    • 评论:8条