Practical 4: Write a program to find length of string and print second half of the string.

Program:

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:


Comments

Popular posts from this blog

Practical 11 : Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream

Practical 9 : Write an interactive program to print a string entered in a pyramid form. For instance, the string “stream” has to be displayed as follows: