luyantl 发表于 2018-9-19 23:15:49

StringBUffer方法

public class StringBufferDemo01
{
        public static void main(String[] args)
        {
                StringBuffer buf=new StringBuffer();
                buf.append("Hello");
                buf.append("World").append("!!!");
                System.out.println(buf);
        }
}

luyantl 发表于 2018-9-19 23:19:04

buf=buf.append("Hellp")这样写也准确

luyantl 发表于 2018-9-19 23:26:12

public class StringBufferDemo02
{
        public static void main(String[] args)
        {
                StringBuffer buf=new StringBuffer();
                buf.append("累加");
                for (int x=0;x<=100 ;x++ )
                {
                        buf.append(x);
                        System.out.print(buf+"\t");
                }
        }
}

luyantl 发表于 2018-9-19 23:58:09

//StringBuffer类学习,习题
class StringBufferAdd
{
        public static void bufAdd(StringBuffer temp)
        {
                //StringBuffer.append("a");
                for(int x=0;x<=25;x++)
                {
                        char tempa='a';
                        tempa+=x;
                        temp=temp.append(tempa);
                        System.out.print(tempa+"\t");
                }
        }
}
//************************************************
class StringBufferReverse                //将字符反转
{
        public static void bufReverse(StringBuffer temp)
        {
                temp=temp.reverse();
                System.out.println();
                System.out.println(temp);
        }

}
//***************************************************
classStringBufferDel
{
        public static void bufDel(StringBuffer temp)
        {
                temp.delete(0,4);
                System.out.println(temp);
        }
       
}
//***************************************************
public class StringBufferDemo03
{
        public static void main(String[] args)
        {
                StringBuffer buf=new StringBuffer();
                //buf.append('a');
                StringBufferAdd.bufAdd(buf);
                StringBufferReverse.bufReverse(buf);
                StringBufferDel.bufDel(buf);
        }
}

luyantl 发表于 2018-9-20 00:16:05

import java.util.*;
public class RandomDemo1
{
        public static void main(String[] args)
        {
                Random ran=new Random();
                print(ran);
        }
        public static void print(Random temp)
        {
                for (int x=0;x<5 ;x++ )
                {
                        System.out.println(temp.nextInt(30));
                }
        }
}



//利用Random哦对产五个随机数
页: [1]
查看完整版本: StringBUffer方法