0% found this document useful (0 votes)
3 views3 pages

AOOP Practical 13

The document contains two Java programs demonstrating the use of various String class methods. The first program showcases methods like charAt(), contains(), length(), and split(), while the second program illustrates the format() method. Both programs include code snippets and their expected outputs.

Uploaded by

saritaanil315
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

AOOP Practical 13

The document contains two Java programs demonstrating the use of various String class methods. The first program showcases methods like charAt(), contains(), length(), and split(), while the second program illustrates the format() method. Both programs include code snippets and their expected outputs.

Uploaded by

saritaanil315
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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:

You might also like