From e621cde19e57052359b1da442f0c2c2f22bf78f6 Mon Sep 17 00:00:00 2001 From: vivek sharma <45270024+vvksharrma@users.noreply.github.com> Date: Sun, 24 Oct 2021 17:45:15 +0530 Subject: [PATCH] Create evenString.java Given a string of even length, return the first half. So the string "CatDog" yields "Cat". If the string length is odd number then return null. --- Java Basic Program/evenString.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Java Basic Program/evenString.java diff --git a/Java Basic Program/evenString.java b/Java Basic Program/evenString.java new file mode 100644 index 0000000..39f00a6 --- /dev/null +++ b/Java Basic Program/evenString.java @@ -0,0 +1,17 @@ + +class main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String str = in.nextLine(); + System.out.println(firstHalf(str)); + } + + static String firstHalf(String s) { + int l = s.length(); + + if((l & 1) == 1) + return null; + else + return s.substring(0, l/2); + } +}