Pascal Triangle Pattern Program in Java

Pascal triangle in java. In the Java programming language, the right pascal triangle pattern is used. The asterisk right side pascal triangle will be printed by this application. In the java programming language, the asterisk is used to print this right angle pascal program. Beginners in the field of software development may use the triangle pascal program in Java.

For Loop Definition in Java Program

The “for” loop in Java is an entry-controlled loop that allows a user to iteratively run a block of statement(s) for a defined number of times. The number of iterations is determined by the test condition specified within the “for” loop. The Java “for” loop is one of the simplest Java loops to grasp. A “For” Loop is used to iterate over a specified block of code a predetermined number of times.

sc.nextint() in Java

The nextLine() function of the java. util. Scanner moves this scanner past the current line and returns the input that was skipped. This function returns the remainder of the current line, minus any line separators at the end. The java.util. Scanner class’s nextInt(radix) function scans the next token of the input as an Int. If the translation is successful, the scanner moves beyond the matching input. If the argument radix is not supplied, it functions identically to nextInt(radix), with the radix presumed to be the default radix.

Pascal Definition

A pascal is a unit of pressure, with one pascal equaling one newton of force applied to one square metre. A pascal is a unit of pressure, with one pascal equaling one newton of force applied to one square metre.

import java.util.Scanner; 
public class Main
{ 
public static void main(String[] args) 
{ 
int i, j, rows; 
Scanner sc = new Scanner(System.in); 
System.out.print("Enter the numbers"); 
rows = sc.nextInt(); 
for (i= 0; i<= rows-1; i++) 
{ 
for (j=0; j<=i; j++) 
{ 
System.out.print("*"+ " "); 
} 
System.out.println(""); 
} 
for (i=rows-1; i>=0; i--) 
{ 
for(j=0; j <= i-1;j++) 
{ 
System.out.print("*"+ " "); 
} 
System.out.println(""); 
} 
} 
} 

Output:

enter the numbers5

*

* *

* * *

* * * *

* * * * *

* * * *

* * *

* *

*