Traditional Culture Encyclopedia - Weather forecast - Writing programs in Java
Writing programs in Java
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer s=new StringBuffer("The weather is not very good recently, sometimes I haven't seen the moon for several days, but today the moon is in the sky, and the sky is cloudless");
StringBuffer s1=new StringBuffer("The moon is in the sky, and the sky is cloudless");
s=s.delete(s.lastIndexOf("The bright moon is in the sky, the blue sky is cloudless"),s.length());//Remove "The bright moon is in the sky, the blue sky is cloudless" and save it to StringBuffer s1 .
System.out.println(s);
s1=s1.delete(3,s1.length());//Delete all characters of s1 starting from the third character character.
System.out.println(s1);
StringBuffer s2=new StringBuffer(s.substring(7,10));//Get a substring s2 of s (from Take out 3 characters starting from the 7th one).
System.out.println(s2);
s2.reverse();//Reverse substring s2.
System.out.println(s2);
s1.append(s2);//Add s2 to the end of s1.
System.out.println("The length of the string '"+s1+"' is: "+s1.length());//Calculate the length L of the new string and print out the result.
}
}
The result is:
The weather has not been very good recently, and sometimes the moon cannot be seen for several days.
But today it is
the bright moon
, sometimes
sometimes,
the length of the string 'there was a bright moon at that time' is :6
- Related articles
- Climatic characteristics of the Arctic region
- weekly diary of a smart little monkey
- Independent family car with both face value and strength, and the landing price is about100000.
- I hate rainy weather-but it often appears-and I often feel depressed-what should I do?
- Why is it windy in spring?
- Can Baidu watch the weather?
- Zhaqu weather forecast
- Fashion Story | Classic items in autumn and winter
- I want to watch the Spring Festival couplets.
- Why do we always remember the wild fruits we ate when we were young?