-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathstringpattern10.java
More file actions
33 lines (30 loc) · 887 Bytes
/
Copy pathstringpattern10.java
File metadata and controls
33 lines (30 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
class StringPattern10
{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str = s.nextLine(); // Input String
int l = str.length();
int n = s.nextInt(); //Input no. of lines to be printed
int index = 0;
for(int i=0;i<n;i++) { // Loop to print rows.
for(int j=n-1;j>i;j--) { // Loop to print spaces
System.out.print(" ");
}
for(int k=0;k<=i;k++) { // Loop to print value
System.out.print(str.charAt(index++));
if(index == l) {
index = 0;
}
}
System.out.println();
}
}
}
// Sample Input :- PatternHouse
// 5
// P
// at
// ter
// nHou
// sePat