pLs answer fast no spamming
Attachments:
Answers
Answered by
1
Answer:
this is loop program
use for loop inside one nested loop and track your i and j then print
external i when end then put new line
do that yourself
Answered by
8
Question:-
- WAP to print the following pattern
1 1 1 1 1 1
1 2 2 2 2 2
1 2 3 3 3 3
1 2 3 4 4 4
1 2 3 4 5 5
1 2 3 4 5 6
Answer:-
//Program to print the square pattern
package Programmer;
public class SquarePatt
{
public static void main (String ar [])
{
for (int I=1;I<=6;I++)
{
for(int j=1;j<=I;j++)
{
System.out.print(j+" ");
}
for(int j=I;j<=5;j++)
{
System.out.print(I+" ");
}
System.out.println();
}
}
}
_________
Variable Description:-
- I:- loop variable
- j:- loop variable
______
Explaination:-
- The program runs I loop from 1 to no. of lines in the pattern(here 6)
- Then j loop runs from 1 to I
- Since the pattern starts with different number and ends with same numbers.. so in this loop we need to print j loop value
- J loop terminates soon when it is greater than I
- Another j loop runs but from i to 5
- Here we print I
- j loop terminates
- System.out.println() brings the cursor to next line
- I loop terminates soon when it 8s greater than 6
- Yay! Program ended! You got a desired pattern!!
_
• Output attached
Attachments:
Similar questions