Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Pattern printing

Rating
-
Sold
-
Pages
65
Grade
A
Uploaded on
04-12-2024
Written in
2024/2025

Pattern printing in programming refers to creating patterns or designs using loops and control structures. It's a common exercise for beginners to get hands-on with nested loops, conditional statements, and their syntactical understanding. Here's a brief overview: ### Concepts 1. **Loops**: - **For Loop**: Used when the number of iterations is known. - **While Loop**: Used when the number of iterations is not known in advance. 2. **Control Structures**: - **If-Else Statements**: Used to create conditions within loops. ### Examples #### Star Pattern Creating a right-angled triangle with stars. ```python n = 5 for i in range(1, n+1): print('*' * i) ``` **Output**: ``` * ** *** **** ***** ``` #### Number Pattern Creating a number pattern. ```python n = 5 for i in range(1, n+1): for j in range(1, i+1): print(j, end=" ") print() ``` **Output**: ``` 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 ```

Show more Read less
Institution
Course

Content preview

Star Pattern
In
ProgrammIng
Language
Created by
atISh Kumar Sahu

,STAR PATTERN – 01
* * * * * * * * * *
public class Main {
public static void main (String args[]) {
int r = 10;
for(int i = 1; i <= r; i++) {
System.out.print(“* ”);
}
}
}
STAR PATTERN – 02
**********
public class Main {
public static void main (String args[]) {
int r = 10;
for(int i = 1; i <= r; i++) {
System.out.print(“*”);
}
}
}

,STAR PATTERN – 03
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
public class Main {
public static void main (String args[]) {
int r = 10;
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= r; j++) {
System.out.print(“* ”);
}
System.out.println();
}
}
}

, STAR PATTERN – 04
* * * * *
* *
* *
* *
* * * * *
public class Main {
public static void main (String args []) {
int r = 10;
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= r; j++) {
if(i == 1 || j == 1 || i == r || j == r) {
System.out.print(“* ”);
} else {
System.out.print(“ ”);
}
}
}
}
}

Written for

Institution
Course

Document information

Uploaded on
December 4, 2024
Number of pages
65
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$6.79
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
praveenjrnp888

Get to know the seller

Seller avatar
praveenjrnp888 IIT DELHI
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions