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));
}
}
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:
thanks ....its a very helpful to me to understand ....
ReplyDeleteNo this is not helpful for me because it only prints 1st half of the string not the second half.
ReplyDeleteimport java.util.Scanner;
ReplyDeleteclass 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);
}
}