Java程序打印镜像反向直角三角形星形图案

编写一个Java程序,使用for循环打印镜像反向直角三角形星形图案。这个镜像反向直角三角形的例子根据If条件打印星号或空格。

package ShapePrograms;

import java.util.Scanner;

public class RevMirroredRightTri1 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Reverse Mirrored Right Triangle Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Reverse Mirrored Right Triangle Star Pattern");
		
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= rows; j++ ) 
			{
				if(j < i)
				{
					System.out.print(" ");
				}
				else
				{
					System.out.print("*");
				}
			}
			System.out.println();
		}
	}
}
Java Program to Print Reverse Mirrored Right Triangle Star Pattern

在这个镜像反向直角三角形星形图案 程序中,我们用 while 循环 替换了 for 循环

package ShapePrograms;

import java.util.Scanner;

public class RevMirroredRightTri2 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Reverse Mirrored Right Triangle Rows = ");
		int rows = sc.nextInt();
		

		int i = 1, j;
		while( i <= rows ) 
		{
			j = 1 ;
			while(j <= rows) 
			{
				if(j < i)
				{
					System.out.print(" ");
				}
				else
				{
					System.out.print("*");
				}
				j++;
			}
			System.out.println();
			i++;
		}
	}
}
Enter Reverse Mirrored Right Triangle Rows = 10

**********
 *********
  ********
   *******
    ******
     *****
      ****
       ***
        **
         *

Java程序使用do while循环打印镜像反向直角三角形星形图案

package ShapePrograms;

import java.util.Scanner;

public class RevMirroredRightTri3 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Reverse Mirrored Right Triangle Rows = ");
		int rows = sc.nextInt();
		

		int i = 1, j;
		do
		{
			j = 1 ;
			do 
			{
				if(j < i)
				{
					System.out.print(" ");
				}
				else
				{
					System.out.print("*");
				}
			} while(++j <= rows);
			System.out.println();
		} while( ++i <= rows );
	}
}
Enter Reverse Mirrored Right Triangle Rows = 14

**************
 *************
  ************
   ***********
    **********
     *********
      ********
       *******
        ******
         *****
          ****
           ***
            **
             *

在这个Java示例中,RevMirroredRightTriangle函数打印给定符号的镜像反向直角三角形图案。

package ShapePrograms;

import java.util.Scanner;

public class RevMirroredRightTri4 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Reverse Mirrored Right Triangle Rows = ");
		int rows = sc.nextInt();
		
		System.out.print("Character for Reverse Mirrored Right Triangle Pattern = ");
		char ch = sc.next().charAt(0);
		

		RevMirroredRightTriangle(rows, ch);		
	}
	
	public static void RevMirroredRightTriangle(int rows, char ch) {
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= rows; j++ ) 
			{
				if(j < i)
				{
					System.out.print(" ");
				}
				else
				{
					System.out.print(ch);
				}
			}
			System.out.println();
		}
	}
}
Enter Reverse Mirrored Right Triangle Rows = 17
Character for Reverse Mirrored Right Triangle Pattern = #

#################
 ################
  ###############
   ##############
    #############
     ############
      ###########
       ##########
        #########
         ########
          #######
           ######
            #####
             ####
              ###
               ##
                #