Star Pattern Program in Java Using For Loop

Star pattern in java. This pattern print asterisk pattern in left side pascal pattern. Exactly pascal program is printed in left side facing in the output for beginners in java language

sc.nextint() in Java Program

The Java Scanner class’s nextInt() function is used to scan the next token of the input as an int. 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.

For Loop in Java

In Java, a “for” loop is an entry-controlled loop that allows a user to iteratively run a block of statement(s) for a specified number of times. The test condition supplied within the “for” loop determines the number of iterations. The Java “for” loop is one of the most basic Java loops to understand. A “For” Loop is used to loop over a certain section of code a number of times.

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

Output:

enter the numbers 5

        *

      **

    ***

  ****

*****

  ****

    ***

      **

        *