Pattern Question In Java
Sample 1
i stars n
n = 3 0 1 3
* 1 2 3
** 2 3 3
***
i = 0 to 2 {0, 1, 2}
stars = i + 1
Sample 1
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
i = 0 to 2 {0, 1, 2} for(int i = 0; i < n; i++) {
int stars = i + 1;
stars = i + 1 for(int j = 0; j < stars; j++) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
Sample 2
i stars n
n = 3 0 3 3
*** 1 2 3
** 2 1 3
*
i = 0 to 2 {0, 1, 2}
stars = n - i
Sample 2
import java.util.Scanner;
class Main {
public static void main(String[] args)
{
i = 0 to 2 {0, 1, 2} Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
stars = n - i for(int i = 0; i < n; i++) {
int stars = n - i;
for(int j = 0; j < stars; j++) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
Sample 3
First 3 rows Last 3 rows
i stars n i stars n
n = 3
0 1 3 0 3 3
*
** 1 2 3 1 2 3
*** 2 3 3 2 1 3
**
* i = 0 to 2 {0, 1, i = 0 to 2 {0, 1,
2} 2}
stars = n - i stars = n - i
Sample 3
i = 0 to 2 {0, 1, 2}
stars = i + 1
i = 1 to 2 {1, 2}
stars = n - i
Sample 3
import java.util.Scanner; for(int i = 1; i <
class Main { n; i++) {
public static void int stars = n -
main(String[] args) { i;
Scanner sc = new for(int j = 0; j
Scanner(System.in); < stars; j++) {
int n = sc.nextInt();
for(int i = 0; i < n; i++) { System.out.print("*");
int stars = i + 1; }
for(int j = 0; j < stars;
j++) { System.out.print("\n");
System.out.print("*"); }
} }
System.out.print("\n"); }
}
Question
To print a solid and hollow rectangle using stars
Question
Hollow Diamond Inscribed in a Rectangle
Question
To print the various below shown Pyramid pattern
programs using stars
Question
Pascal’s Triangle Pattern Program
Question
Floyd’s Triangle Pattern Program
Question
To print the various below shown Pyramid pattern
programs using numbers
Question
To print the various below given Diamond pattern
programs using star
Question
To print the various below given palindromic pyramid
pattern programs using numbers and alphabet
Question
To print the various below given Diamond pattern
programs using numbers and stars