Manu

Saturday, November 19, 2016

WAP to find length of string and print second half of the string


CODE:
import java.util.*;
class SubString
{
     public static void main(String m[])
    {
         Scanner in=new Scanner(System.in);
         String s=new String();
         System.out.println("Enter a String :");
         s=in.next();
         int l=s.length();
         System.out.println("Length of the string "+s+" is "+l);
         System.out.println("Your sub String is:"+s.substring(l/2));
     }
}

OUTPUT:

3 comments:

  1. thanks ....its a very helpful to me to understand ....

    ReplyDelete
  2. No this is not helpful for me because it only prints 1st half of the string not the second half.

    ReplyDelete
  3. import java.util.Scanner;
    class prog4
    {
    public static void main(String[] args)
    {
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter a String: ");
    String t = scan.nextLine();

    String sub ="";
    sub =t.substring(t.length()/2);

    System.out.println("Second half: "+sub);
    }
    }

    ReplyDelete