- <pre code_snippet_id="94876" snippet_file_name="blog_20131203_1_8551646" name="code" class="java">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
- *
- * *
- * * *
- * * * *
- * * * * *
- 倒过来的三角
- * * * * *
- * * * *
- * * *
- * *
- *
- </pre><br>
- <pre code_snippet_id="94876" snippet_file_name="blog_20131203_2_2062106" name="code" class="java">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
- *
- ***
- *****
- *******
- *********
- ***********
- *************
- ***************
- *****************
- *******************
- </pre><br>
- <pre code_snippet_id="94876" snippet_file_name="blog_20131203_3_6347484" name="code" class="java">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();
- }
- }
- }
- </pre><br>
- <pre code_snippet_id="94876" snippet_file_name="blog_20131203_4_1189271" name="code" class="java">请输入行数
- 7
- *
- ***
- *****
- *******
- *********
- ***********
- *************
- ***********
- *********
- *******
- *****
- ***
- *
- </pre><br>
- <pre code_snippet_id="94876" snippet_file_name="blog_20131203_5_3555822" name="code" class="java">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
- * * * * * * * * * *
- * *
- * *
- * *
- * *
- * *
- * *
- * *
- * *
- * * * * * * * * * * </pre><br>
- 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();
- }
- }
- }
- *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * *
- <pre></pre>
- <pre></pre>
java 打印各种 图形
最新推荐文章于 2023-04-16 09:57:43 发布