Java Program to Find Length of String


Aim :- Write a Java Program to Find Length of String and Print Half of The String.


Java Program :


import java.util.*;
class j5_1{
     public static void main(String args[])
     {
          Scanner s=new Scanner(System.in);
          System.out.println("\nEnter String : ");
          String str=s.next();
          System.out.println("\nString Length is : "+str.length());
          int l=str.length();
          int l1=l/2;
          String s2=str.substring(0,l1);
          System.out.print("\nHalf String is : "+s2);
     }
}

Output : 





Post a Comment

0 Comments