AOOP Practical 13
AOOP Practical 13
1
Aim: Write a java program to demonstrate use of “String” class methods: chatAt(),
contains(), length(), split()
Code:
class string
{
public static void main(String args[])
{
String name="Bhavya";
String s1="Panchal Bhavya Hasmukhbhai";
char ch=name.charAt(0);
System.out.println("charAt="+ch);
System.out.println("contain="+name.contains("Panchal"));
System.out.println("string length is:"+name.length());
String[]words=s1.split("\\s");
System.out.println("splitted string:");
for(String w:words)
{
System.out.println(w);
}
}
}
Output:
Practical:13.2
Aim: Write a java program to demonstrate use of “String” class methods: format()
Code:
import java.util.*;
class form
{
public static void main(String args[])
{
String s=String.format("value is=%d",10);
String s1=String.format("float value=%f",10.5);
String s2=String.format("day=%td",new Date());
String s3=String.format("month=%tB",new Date());
String s4=String.format("year=%ty",new Date());
String s5=String.format("time in hour=%tl",new Date());
String s6=String.format("time in minute=%tm",new Date());
String s7=String.format("time in am/pm=%tp",new Date());
String s8=String.format("month=%tm"+"",new Date());
System.out.println(s);
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
System.out.println(s4);
System.out.println(new Date());
System.out.println(s5);
System.out.println(s6);
System.out.println(s7);
System.out.println(s8);
}
}
Output: