Patterns in Dart

 import 'dart:io';


/// Parameters to find
/// Number of Outer loop runs = Total number of Rows will count in desired pattern
/// Number of Inner loop runs = Total number of Columns will count in desired pattern
/// What to print = stdout.write(" ");

void main() {
/// Pattern 1
// for (int i = 1; i <= 5; i++) { //Outer loop
// for (int j = 1; j <= 5; j++) { //Inner loop
// stdout.write("* "); //In Output, number of rows are 5 so that Outer loop will be i=5(five) times loop
// } //In Output, number of Columns are 5 so that Inner loop will be j=5(five) times loop
// stdout.write("\n"); //Logic: Number of Rows = value of "i" in Outer loop
// } //Logic: Number of Columns = value of "j" in Inner loop

//Output should be:
// * * * * *
// * * * * *
// * * * * *
// * * * * *
// * * * * *

///NOTE : If Row's number is repeated constantly then Outer loop variable "i" will print(stdout.write("i")) and
///When Column's number is repeated constantly then Inner loop variable "j" will print(stdout.write("j"))
/// Pattern 2
////In Output, every Row's number is constantly repeated so that "i" will print multiple times
// for (int i = 1; i <= 5; i++) {
// for (int j = 1; j <= 5; j++) {
// stdout.write("$i");
// }
// stdout.write("\n");
// }

//Output: 1 1 1 1 1
// 2 2 2 2 2
// 3 3 3 3 3
// 4 4 4 4 4
// 5 5 5 5 5

/// Pattern 3
// //In Output, every Column's number is constantly repeated(increasing Figure) and Row's number is constantly
// increasing(changing) So that "j"(inner loop) will print multiple times
// for(int i=1; i<=5; i++) {
// for(int j=1; j<=5; j++) {
// stdout.write("$j");
// }
// stdout.write("\n");
// }

//Output: 1 2 3 4 5
// 1 2 3 4 5
// 1 2 3 4 5
// 1 2 3 4 5
// 1 2 3 4 5

/// Pattern 4
//In Output, every Column's number is constantly repeated(decreasing Figure) and Row's number is constantly
//decreasing(changing) So that "j"(inner loop) will print multiple times
// for(int i=5; i>=1; i--) {
// for(int j=5; j>=1; j--) {
// stdout.write(j);
// }
// stdout.write("\n");
// }

/// Pattern 5
// char i, j;
// for(i="A"; i<="E"; i++) {
// for(j="A"; j<="E"; j++) {
// stdout.write(i);
// }
// stdout.write("\n");
// }

//OUTPUT: A A A A A
// B B B B B
// C C C C C
// D D D D D
// E E E E E

/// Pattern 6
// int i,j;
// for(int i=1; i<=5; i++) {
// for(int j=1; j<=i; j++) {
// stdout.write("* ");
// }
// stdout.write("\n");
// }
//OUTPUT: *
// * *
// * * *
// * * * *
// * * * * *

/// Pattern 7
// for(int i=1; i<=5; i++) {
// for(int j=1; j<=i; j++) {
// stdout.write(i);
// }
// stdout.write("\n");
// }
//OUTPUT: 1
// 22
// 333
// 4444
// 55555

/// Pattern 8
// for(int i=1; i<=5; i++) {
// for(int j=1; j<=i; j++) {
// stdout.write(j);
// }
// stdout.write("\n");
// }
//OUTPUT: 1
// 12
// 123
// 1234
// 12345

/// Pattern 9
// for(int i=1; i<5; i++) {
// for(int j=5; j>i; j--) {
// stdout.write("* ");
// }
// stdout.write("\n");
// }
//OUTPUT: * * * * *
// * * * *
// * * *
// * *
// *

/// Pattern 10
// for(int i=1; i<=5; i++) {
// for(int j=5; j>=i; j--) {
// stdout.write(i);
// }
// stdout.write("\n");
// }
//OUTPUT: 11111
// 2222
// 333
// 44
// 5

/// Pattern 11
// for(int i=1; i<=5; i++) {
// for(int j=5; j>=i; j--) {
// stdout.write(j);
// }
// stdout.write("\n");
// }
//OUTPUT: 54321
// 5432
// 543
// 54
// 5

/// Pattern 12
// for(int i=5; i>=1; i--) {
// for(int j=1; j<=i; j++) {
// stdout.write(i);
// }
// stdout.write("\n");
// }
//OUTPUT: 55555
// 4444
// 333
// 22
// 1

/// Pattern 13
// for(int i=5; i>=1; i--) {
// for(int j=1; j<=i; j++) {
// stdout.write(j);
// }
// stdout.write("\n");
// }
//OUTPUT: 12345
// 1234
// 123
// 12
// 1

/// Pattern 14
/// In C language programming
// for(int i=1; i<=5; i++) {
// for(int j=5; j>=i; j--) {
// printf("%c",i+65);
// }
// printf("\n");
// }
//OUTPUT: A A A A A
// B B B B
// C C C
// D D
// E

/// Pattern 15
// int i,s,j,n = 5;
// for(i=1; i<=n; i++) { //Outer loop
// for(s=n-1; s>=i; s--) { //Space loop
// stdout.write(" ");
// }
// for(j=1; j<=i; j++) { //Inner print loop
// stdout.write("*");
// }
// stdout.write("\n");
// }
//OUTPUT: *
// **
// ***
// ****
// *****

/// Pattern 16
int i,s,j,n = 5;
for(i=1; i<=n; i++) {
for(s=n-1; s>=i; s--) {
stdout.write(" ");
}
for(j=1; j<=i; j++) {
stdout.write("* ");
}
stdout.write("\n");
}
//OUTPUT: *
// * *
// * * *
// * * * *
//* * * * *

/// Pattern 17
// int i,s,j,n = 5;
// for(i=1; i<=n; i++) {
// for(s=n-1; s>=i; s--) {
// stdout.write(" ");
// }
// for(j=1; j<=i; j++) {
// stdout.write(i);
// }
// stdout.write("\n");
// }
//OUTPUT: 1
// 22
// 333
// 4444
// 55555

/// Pattern 18
// int i,j,s,n = 5;
// for(i=1; i<=n; i++) {
// for(s=n-1; s>=i; s--) {
// stdout.write(" ");
// }
// for(j=1; j<=i; j++) {
// stdout.write(j);
// }
// stdout.write("\n");
// }
//OUTPUT: 1
// 12
// 123
// 1234
// 12345

/// Pattern 19
// int i,j,s,n = 5;
// for(i=1; i<=n; i++) {
// for(s=n-1; s>=i; s--) {
// stdout.write(" ");
// }
// for(j=1; j<=i; j++) {
// stdout.write("$j ");
// }
// stdout.write("\n");
// }
//OUTPUT: 1
// 1 2
// 1 2 3
// 1 2 3 4
// 1 2 3 4 5

/// Pattern 20
// int i,j,s,n = 5;
// for(i=n; i>=1; i--) {
// for(s=n-1; s>=i; s--) {
// stdout.write(" ");
// }
// for(j=1; j<=i; j++) {
// stdout.write("*");
// }
// stdout.write("\n");
// }
//OUTPUT: *****
// ****
// ***
// **
// *

/// Pattern 21
// int i,j,s,n = 5;
// for(i=n; i>=1; i--) {
// for(s=n-1; s>=i; s--) {
// stdout.write(" ");
// }
// for(j=1; j<=i; j++) {
// stdout.write("* ");
// }
// stdout.write("\n");
// }
//OUTPUT: * * * * *
// * * * *
// * * *
// * *
// *

/// Pattern 22
// int i,j,s,n = 5;
// for(i=n; i>=1; i--) {
// for(s=n-1; s>=i; s--) {
// stdout.write(" ");
// }
// for(j=1; j<=i; j++) {
// stdout.write("$i ");
// }
// stdout.write("\n");
// }
//OUTPUT: 5 5 5 5 5
// 4 4 4 4
// 3 3 3
// 2 2
// 1

/// Pattern 23
// int i,j,s,n = 5;
// for(i=n; i>=1; i--) {
// for(s=n-1; s>=i; s--) {
// stdout.write(" ");
// }
// for(j=1; j<=i; j++) {
// stdout.write("$j ");
// }
// stdout.write("\n");
// }
//OUTPUT: 1 2 3 4 5
// 1 2 3 4
// 1 2 3
// 1 2
// 1

/// Pattern 24
// int i,j,n = 5;
// for(i=1; i<=n; i++) {
// for(j=n; j>=1; j--) {
// if(i>=j) {
// stdout.write("* ");
// } else {
// stdout.write(" ");
// }
// stdout.write("\n");
// }
// }

}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Pagination with Bloc Pattern in Flutter

If_Else_Example