-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path36.2 String Middle element.java
More file actions
40 lines (30 loc) · 1009 Bytes
/
36.2 String Middle element.java
File metadata and controls
40 lines (30 loc) · 1009 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
/*
Jashu, Preeti, and Rita where playing a game, where they call each other randomly and they need to tell their middle character of their names. First Preeti called Jashu then Jashu called Rita then Rita called Jashu
Input Format
Jashu
Constraints
Declare name in the form of String
If the string name has odd no of character then print the middle character, if the string name has even no of character then print the middle two characters
Output Format
s
Sample Input 0
Jashu
Sample Output 0
s
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc =new Scanner(System.in);
String s = sc.next();
int i = s.length();
if(i%2!=0)
{
System.out.print(s.charAt(i/2));
}
else
System.out.print(s.charAt((i/2)-1)+""+s.charAt(i/2));
}
}