Problem: Draw rectangle with two triangle java program
Sample Input:
5
Sample Output:
*####
**###
***##
****#
*****
Solve:
Lets see the following Code:
Sample Input:
5
Sample Output:
*####
**###
***##
****#
*****
Solve:
Lets see the following Code:
// ADLabs import java.util.Scanner; public class NastedForLoop { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter any Int Num:"); int n = sc.nextInt(); System.out.println(); // Rectangle with two triangle for (int i = 1; i <= n; i++) { int j; for (j = 1; j <= i; j++) { System.out.print("*"); } for (int j2 = j; j2 <= n; j2++) { System.out.print("#"); } System.out.println(); } sc.close(); } }
Console:
Enter any Int Num:5
*####
**###
***##
****#
*****
Happy Coding
-@D