Skip to content

Commit b65e20e

Browse files
Create 36.2 String Middle element.java
1 parent d4afcd3 commit b65e20e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

36.2 String Middle element.java

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
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
3+
4+
Input Format
5+
6+
Jashu
7+
8+
Constraints
9+
10+
Declare name in the form of String
11+
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
12+
Output Format
13+
14+
s
15+
16+
Sample Input 0
17+
18+
Jashu
19+
Sample Output 0
20+
21+
s
22+
*/
23+
import java.io.*;
24+
import java.util.*;
25+
26+
public class Solution {
27+
28+
public static void main(String[] args) {
29+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
30+
Scanner sc =new Scanner(System.in);
31+
String s = sc.next();
32+
int i = s.length();
33+
if(i%2!=0)
34+
{
35+
System.out.print(s.charAt(i/2));
36+
}
37+
else
38+
System.out.print(s.charAt((i/2)-1)+""+s.charAt(i/2));
39+
}
40+
}

0 commit comments

Comments
 (0)