Java 打印指数增长的星形图案程序

使用 for 循环编写一个 Java 程序来打印指数增长的星形图案。它使用嵌套的 for 循环,第一个 for 循环从零迭代到给定的行数。然后,Java 嵌套循环在每次迭代中从 1 迭代到 i 的幂值,以打印指数增长的星形图案。

package ShapePrograms;

import java.util.Scanner;

public class ExponentiallyIncrease1 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Exponentially Increased Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Exponentially Increased Rectangle Star Pattern");
		
		for (int i = 0; i < rows; i++ ) 
		{
			for (int j = 1 ; j <= Math.pow(2, i); j++ ) 
			{
				System.out.print("*");
			}
			System.out.println();
		}
	}
}
Java Program to Print Exponentially Increased Star Pattern

在此 Java 指数增长的星形图案程序中,我们将for 循环替换为while 循环

package ShapePrograms;

import java.util.Scanner;

public class ExponentiallyIncrease2 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Exponentially Increased Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Exponentially Increased Rectangle Star Pattern");
		
		int i = 0, j;
		while( i < rows) 
		{
			j = 1 ;
			while ( j <= Math.pow(2, i) ) 
			{
				System.out.print("*");
				j++;
			}
			System.out.println();
			i++ ;
		}
	}
}
Enter Exponentially Increased Pattern Rows = 7
Printing Exponentially Increased Rectangle Star Pattern
*
**
****
********
****************
********************************
****************************************************************

使用 do while 循环打印指数增长星形图案的 Java 程序

package ShapePrograms;

import java.util.Scanner;

public class ExponentiallyIncrease3 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i = 0, j;
		
		System.out.print("Enter Exponentially Increased Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Exponentially Increased Rectangle Star Pattern");
	
		do
		{
			j = 1 ;
			do
			{
				System.out.print("*");
			} while ( ++j <= Math.pow(2, i) );
			System.out.println();
		} while( ++i < rows) ;
	}
}
Enter Exponentially Increased Pattern Rows = 4
Printing Exponentially Increased Rectangle Star Pattern
*
**
****
********

在此 Java 示例中,ExponentiallyIncreasedPattern 函数打印给定符号的指数增长模式。

package ShapePrograms;

import java.util.Scanner;

public class ExponentiallyIncrease4 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Exponentially Increased Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.print("Enter Character for Exponentially Increased Pattern = ");
		char ch = sc.next().charAt(0);
		
		System.out.println("Printing Exponentially Increased Rectangle Star Pattern");
		ExponentiallyIncreasedPattern(rows, ch);
		
	}
	
	public static void ExponentiallyIncreasedPattern(int rows, char ch) {
		for (int i = 0; i < rows; i++ ) 
		{
			for (int j = 1 ; j <= Math.pow(2, i); j++ ) 
			{
				System.out.print(ch);
			}
			System.out.println();
		}
	}
}
Enter Exponentially Increased Pattern Rows = 7
Enter Character for Exponentially Increased Pattern = #
Printing Exponentially Increased Rectangle Star Pattern
#
##
####
########
################
################################
################################################################