Tuesday, 29 August 2017

How to find second half of given string in core java program

Write a program to find length of string and print second half of the string

Program

import java.util.Scanner;
class String_second_half
{       
          public static void main(String args[])
          {
                   Scanner in = new Scanner(System.in);
                   System.out.println("ENTER TO ANY STRING");
                   String Str;
                   Str = in.nextLine();
                   int n =Str.length();
                   int ans = (n/2)+1;
                   System.out.println("String half length is:" + ans);
}

 }

Output

length of string core java

0 comments:

Post a Comment