Middle Three Characters

A string S of length 7 is passed as the input to the program. The program must print the middle three characters as the output.

Example Input/Output:
Input:
brinjal

Output
inj

Python

string = input()
print(string[2:5])

Java

import java.util.*;
public class Hello {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.print(str.substring(2, 5));
    }
}

C

#include <stdlib.h>
#include  <stdio.h>
int main()
{
    char str[8];
    scanf("%s", str);
    printf("%c%c%c", str[2],str[3],str[4]);
}

C++

#include <iostream>
using namespace std;
int main()
{
    string str;
    cin >> str;
    cout << str[2] << str[3] << str[4];
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts. You may also be interested in.