/
RemoveLastFirst.java
57 lines (54 loc) · 1007 Bytes
/
RemoveLastFirst.java
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
46
47
48
49
50
51
52
53
54
55
56
57
/*
Remove First And Last Till End
Given a string S, print the string S removing first and last character till no characters are left.
Boundary Condition :
1 <= Length of string S <= 1000
Input Format:
The first line contains S
Example Input/Output 1:
Input:
water
Output :
water
ate
t
Example Input/Output 2:
Input:
keyboard
Output :
keyboard
eyboar
yboa
bo
*/
import java.util.*;
public class Hello {
public static void main(String[] args) {
//Your Code Here
Scanner sc = new Scanner(System.in);
String a = sc.next();
int n = a.length();
int x = 0;
int j = 0,k=n-1;
if(n%2 == 0)
{
x = n/2;
}
else
{
x = n/2;
x++;
}
// System.out.println(x);
for(int i=0;i<x;i++)
{
for(int r = j;r<=k;r++)
{
System.out.print(a.charAt(r));
}
j++;
k--;
System.out.println();
}
}
}