字符编码--待续

编码:字符串变成字节数组

解码:字节数组变成字符串。

String-->byte[];   str.getBytes(charsetName);

byte[]-->String:  new Strng(byte[],charsetName);

class EncodeDemo{
    public static void main(String[] args) throw Exception{
        String s="你好";
        byte[] b1 = s.getBytes("GBK");
        //System.out.println(Arrays.toString(b1));

        String s1=new String(b1,"GBK");
        System.out.println("s1="+s1);
        
    }
}

练习:

有5个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括姓名,3门课成绩,如zhangsan,30,40,60),计算总成绩,并把学生的信息和计算出的总分数高低顺序存放在磁盘文件"stud.txt"中。

/*
1、描述学术对象
2、定义一个可以操作学生对象的工具类
思想:
1、通过获取键盘录入的数据,将该行信息取出封装成学生对象。
2、因为学生有很多,需要存储,使用集合,对学生的总分排序,可以使用treeset
3、将集合中信息写入到一个文件中
*/
class Student implements Comparable<Student>{
    private String name;
    private double ch,ma,en;
    private double sum;
    Student(String name,double ch,double ma,double en){
        this.
        this.
        this.
        this.
        sum=ch+ma+en;
    }
    public int compareTo(Student s){
        int num=new Integer(this.sum).compareTo(new
    }
    public String getName(){
        return name;
    }
    public int getSum(){
        return sum;
    }

    public int hashCode(){
        return name.hashCode()+sum*78;
    }
    public boolean equals(Object obj){
        if(!(obj instanceof Student)){
            throw new ClassCastException(" ");
        Student s=(Student)obj;
        return this.name.equals(s.name)&&this.sum==s.sum;
        }
    }
    public String toString(){
        return "student:"+name+","+ch+","+ma+","+en;
    }
    }
class StudentInfoTool{
    public static Set<Student> getStudents(){
        BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
        String line=null;
        while((line=bufr.readLine())!=null)){
            if
        }
    }
    public static void main(String[] args){
        
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值