-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_Pattern.java
More file actions
46 lines (40 loc) · 862 Bytes
/
String_Pattern.java
File metadata and controls
46 lines (40 loc) · 862 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
34
35
36
37
38
39
40
41
42
43
44
45
/*
Given an odd length word which should be printed from the middle of the word.
The output should be in the following pattern.
Input: PROGRAM
Output:
G
GR
GRA
GRAM
GRAMP
GRAMPR
GRAMPRO
*/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
for(int i=0;i<str.length();i++,System.out.println())
{
int mid = str.length()/2;
for(int sp=0;sp<3*(str.length()-i-1);sp++)
{
System.out.print(" ");
}
for(int j=0;j<=i;j++)
{
if(mid != str.length())
{
System.out.print(str.charAt(mid++));
}
else{
mid = 0;
System.out.print(str.charAt(mid++));
}
}
}
}
}