In: Computer Science
Given a string str of even length, print out the first half.
Methods to use: substring(), length()
Testing cases:
WooHoo => Woo
HelloThere => Hello
abcdef => abc
ab => a
0123456789 => 01234
kitten => kit
(Note that the sample input test cases are shown before the “=>” and the expected output each test case is after the “=>”.
Your program should print out the expected output only, not the input.)
Source Program:
import java.io.*;
import java.util.Scanner;
class subb
{
public static void main(String args[])
{
Scanner input=new
Scanner(System.in);
String str=input.next();
int len=str.length();
String
str1=str.substring(0,len/2);
System.out.println("\033[1A\033["+len+"C"+"=>"+str1);
}
}
Sample Input and Output: