a java program to print the pattern :
see the attachment ! expecting great answers !
Answers
Program :- {JAVA}
public class RectangularPattern2
{
public static void main(String args [ ] )
{
for (int i = 1; i <= 5, i++)
{
for (int j = 1; j <=5 ; j++)
{
if (i==j)
System.out.println(''\\'');
else
System.out.println(''*'');
}
System.out.println();
}
}
}
REQUIRED PROGRAM:
/* RectangularPattern1.java */
import java.util.Scanner;
public class RectangularPattern1
{
public static void main (String args [ ] )
{
Scanner input = new Scanner (System.in);
System.out.print ("Please enter number of rows:");
int numRows = input.nextInt( );
for ( int i = 1; i <= numRows ; i++)
{
for ( int j = 1; j < numRows; j++)
{
if ( j == numRows)
System.ot.print(i + "");
else
System.out.print("* ");
}
for (int k = 1; k < 1; k++)
{
System.out.println( );
}
input.close( );
}
}
OUTPUT:
Enter number of rows: 5
\ * * * *
* \ * * *
* * \ * *
* * * \ *
* * * * \
KNOW SOMETHING:
Line 12 - Line 28 is the outer loop
Whereas from line 14 to line 20 is the inner loop.
For each iteration of the outer loop, the inner loop is repeated. When the outer loop variable i takes a value that is 1, the inner loop control variable j is repeated within values. Thus output which had been produced is five lines which contains five stars and one slash in each. This process is repeated until the outer loop completes fully.
NOTE:
Either refer the attachment or refer here