【 Java 】从入门到精通

Java核心概念


一.变量和常量

public class helloworld{
    public static void main(String args[]){
        String x="hello_world!";    
        System.out.println(x);
    }
}
public class helloworld{
    public static void main(String args[]){
    String name="Du1in9";
    char sex='男';
    int age=19;
    double price=120.5;
    boolean x=true;
    System.out.println(name+" "+sex+" "+age+" "+price+" "+x);
    }
}
public class helloworld{
    public static void main(String args[]){
        double x=176.2;
        int y=(int)x;
        System.out.println(x);
        System.out.println(y);
    }
}
public class helloworld{
    public static void main(String args[]){
        final double PI=3.1415;
        int r=2;
        System.out.println("圆面积为:"+PI*r*r);
    }
}
public class helloworld{
    public static void main(String args[]){
        System.out.println("hello_motherfucker!");
        //单行注释
        /*多
          行
          注
          释*/
    }
}

二.运算符

public class helloworld{
    public static void main(String args[]){
        double a=1;
        int b=2;
        System.out.println(a+b);
        System.out.println(a-b);
        System.out.println(a*b);
        System.out.println(a/b);
    }
}
        int a=1;
        double b,c,d;
        b=c=d=2;
        b+=a;
        c%=a;
        d/=a;
        a++;
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(a);
        int a=16;
        double b=9.5;
        String str1="hello";
        String str2="world";
        System.out.println("a等于b:" + (a==b));
        System.out.println("a大于b:" + (a>b));
        System.out.println("a小于等于b:" + (a<=b));
        System.out.println("str1等于str2:" + (str1=str2));
        boolean a = true; 
        boolean b = false; 
        boolean c = false; 
        boolean d = true; 
        System.out.println("a&&b " + (a&&b));
        System.out.println("a||b " + (a||b));
        System.out.println("!a " + (!a));
        System.out.println("c^d " + (c^d));
        int score=68;
        String mark = (score>=60)? "及格":"不及格";
        System.out.println("68分:"+mark);

三.流程控制语句

        int x=66;
        if(x<=10){
            System.out.println("x小于等于10");
        }
        else if(x%2==0){
            System.out.println("x大于10的偶数");
        }
        else{
            System.out.println("x大于10的奇数");
        }
        char today='三';
        switch(today){
        case '一':
        case '二':System.out.println("吃油条");break;
        case '三':System.out.println("吃方便面");break;
        default:System.out.println("吃个锤子");
        }
        int i=0;
        while(i<5){
            System.out.println(i);
            i++;
        }
        int i=0;
        do{
            System.out.println(i);
            i++;
        }while(i<5);
        for(int i=0;i<5;i++){
            System.out.println(i);
        }
        for(int i=0;i<10;i++){
            if(i==8){
                break;
            }
            else if(i%2==0){
                continue;
            }
            System.out.println(i);
        }

四.数组

        int[] scores = { 78, 93, 97, 84, 63 };
        System.out.println("第3个成绩为:" +scores[2]);
        for(int i=0;i<scores.length;i++){
            System.out.println(scores[i]);
        }
import java.util.Arrays;
public class helloworld{
    public static void main(String args[]){
        String[] hobbies = { "sports", "game", "movie" };
        int[] x = {1,2,22,34};
        Arrays.sort(hobbies);
        for(int i=0;i<hobbies.length;i++){
            System.out.println(hobbies[i]);
        }
        System.out.println(Arrays.toString(x));
    }
}
        String[] hobbies = { "sports", "game", "movie" };
        for(String x:hobbies){
            System.out.println(x);
        }
        int[][] a={{1,2,3},{6,5,4},{8,9,0}};
        for(int i=0;i<a.length;i++){
            for(int x:a[i]){
                System.out.print(x);
            }
            System.out.println();
        }

五.方法

public class helloworld{
    public void x() {
        System.out.println("hello_motherfucker!");
    }  
    public static void main(String[] args){
        //在 main 方法中调用 print 方法
        helloworld test=new helloworld();
        test.x();
    }
}
    public static void main(String[] args) {    
        helloworld hello = new helloworld();
        double avg = hello.f();    
        System.out.println("平均成绩为:" + avg);
    }
    public double f() {
        double java = 92.5;
        double php = 83.0;
        double x = (java + php) / 2; 
        return x;
        
    }
    public static void main(String[] args) {
        helloworld hello = new helloworld();
        hello.f(94, 81);
    }
    public void f(int j,int h){
        double x = (j+h) / 2.0;
        System.out.print("平均分:"+x);
    }
import java.util.Arrays;
public class helloworld{
    public static void main(String[] args) {
        helloworld hello = new helloworld();
        int[] scores={79,52,98,81};
        int count=hello.sort(scores);
        System.out.println("共有"+count+"个成绩信息!");
    }
    public int sort(int[] scores){
        Arrays.sort(scores);
        System.out.println(Arrays.toString(scores));
        return scores.length;
    }
}
    public static void main(String[] args) {
        helloworld hello = new helloworld();
        //方法的重载
        hello.print();
        hello.print("hello");
        hello.print(18);
    }
    public void print() {
        System.out.println("无参");
    }
    public void print(String x) {
        System.out.println("字符串参数:" + x);
    }
    public void print(int age) {
        System.out.println("整型参数:" + age);
    }

六.类和对象

Telephone.java

package com.du1in9;
public class Telephone {
    float screem;
    float cpu;
    float mem;
    void call(){
        System.out.print(screem+" "+cpu+" "+mem+" ");
        System.out.println("telephone有打电话的功能");
    }
    void message(){
        System.out.print(screem+" "+cpu+" "+mem+" ");
        System.out.println("telephone有发短信的功能");
    }
}

Initial.java

package com.du1in9;
public class Initial {
    public static void main(String[] args){
        Telephone phone=new Telephone();
        phone.call();
        phone.screem=5.0f;
        phone.cpu=1.4f;
        phone.mem=2.0f;
        phone.message();
    }
}

Telephone.java

package com.du1in9;
public class Telephone {
    int var;//成员变量,有初始值
    void x(){
        int var=1;//局部变量,赋初始值
        System.out.println("局部变量 : "+var);
    }
}

Initial.java

package com.du1in9;
public class Initial {
    public static void main(String[] args){
        Telephone phone=new Telephone();
        System.out.println("成员变量 : "+phone.var);
        phone.x();
    }
}

Telephone.java

package com.du1in9;
public class Telephone {
    float screen;
    float cpu;
    float mem;
    public Telephone(){
        System.out.println("无参的构造方法");
    }
    public Telephone(float s,float c,float m){
        System.out.println("有参的构造方法");
        if(s<3.5f){
            System.out.println("你输入的screen参数参数有问题,自动赋值3.5");
            screen=3.5f;
        }else{
            screen=s;
        }
        cpu=c;
        mem=m;
        System.out.println(screen+" "+cpu+" "+mem);
    }
}

Initial.java

package com.du1in9;
public class Initial {
    public static void main(String[] args){
        Telephone phone1=new Telephone();
        Telephone phone2=new Telephone(1.5f,2.5f,4.5f);
    }
}
public class helloworld {
    //静态变量
    String x = "hello_motherfucker!";
    public static void main(String[] args) {
        helloworld demo=new helloworld();
        System.out.println(demo.x);
    }
}
public class helloworld {
    static int x = 86;
    static int y = 92; 
    //静态方法
    public static int sum() { 
        return x+y;
    }
    public static void main(String[] args) {
        int z = helloworld.sum();
        System.out.println("总分:" + z);
    }
}
public class helloworld {
    String name; 
    String sex; 
    static int age;
    public helloworld() { 
        System.out.println("通过构造方法初始化name");
        name = "tom";
    }
    { 
        System.out.println("通过初始化块初始化sex");
        sex = "男";
    }
    static { 
        System.out.println("通过静态初始化块初始化age");
        age = 20;
    }
    public void show() {
        System.out.println("姓名:" + name + ",性别:" + sex + ",年龄:" + age);
    }
    public static void main(String[] args) {
        helloworld hello = new helloworld();
        hello.show();
        
    }
}

七.封装

  • 封装
package com.du1in9;
public class Telephone {
    private float screen;
    public void setScreen(float aScreen){
        screen=aScreen;
    }
    public float getScreen(){
        return screen;
    }
}
package com.du1in9;
public class Initial {
    public static void main(String[] args){
        Telephone phone = new Telephone();
        phone.setScreen(6.0f);
        System.out.println("screen:"+phone.getScreen());
    }
}
  • 包管理类
package com.du1in9;

public class Telephone {
    public Telephone(){
        System.out.println("com.du1in9 Called!");
        }
    }
package com.du1in9.second;

public class Telephone {
    public Telephone(){
        System.out.println("com.du1in9.second Called!");
        }
    }
package com.du1in9;
import com.du1in9.second.Telephone;

public class Initial {
    public static void main(String[] args){
        Telephone phone = new Telephone();
    }
}
  • 访问修饰符
  • this关键字
package com.du1in9;

public class Telephone {
    float screen;
    public float getScreen() {
        return screen;
    }
    public void setScreen(float screen) {
        this.screen = screen;
        this.sendMessage();
    }
    void sendMessage(){
        System.out.println("telephone有发短信的功能");
    }
}
package com.du1in9;

public class Initial {
    public static void main(String[] args){
        Telephone phone = new Telephone();
        phone.setScreen(6.7f);
        System.out.println("screen:"+phone.getScreen());
    }
}
  • 内部类
package com.Du1in9;

public class helloworld{
  private String name = "DU1IN9";
  int age = 20;
    public class Inner {
        String name = "du1in9";
        public void show() { 
            System.out.println("外部类中的name:" + helloworld.this.name);
            System.out.println("内部类中的name:" + Inner.this.name);
            System.out.println("内部类中的name:" + name);
            System.out.println("外部类中的age:" + age);
        }
    }
    public static void main(String[] args) {
        helloworld o = new helloworld (); 
        Inner i = o.new Inner();
        i.show();
    }
}
package com.Du1in9;

public class helloworld {
    private static int score = 84;
    public static class Inner {
        static int score = 91;
        public void show() {
            System.out.println("访问外部类中的score:" + helloworld.score);
            System.out.println("访问内部类中的score:" + Inner.score);
            System.out.println("访问内部类中的score:" + score);
        }
    }
    public static void main(String[] args) {
        Inner i = new Inner();
        i.show();
    }
}
package com.Du1in9;

public class helloworld {
  private String name = "DU1IN9";
  public void show() { 
        class inner {
            int score = 83;
            public int getScore() {
                System.out.println("姓名:" + name + " 加分前的成绩:" + score);
                return score + 10;
            }
        }
        inner i=new inner();
        int newScore = i.getScore();
        System.out.println("姓名:" + name + " 加分后的成绩:" + newScore);
    }
    public static void main(String[] args) {
      helloworld o = new helloworld();
      o.show();
    }
}

八.继承

  • 继承
package com.Du1in9;

public class Animal {
    private int age;
    public String name;
    public void eat(){
        System.out.println("动物具有吃的能力");
    }
}
class Dog extends Animal{
}
package com.Du1in9;

public class helloworld {
    public static void main(String[] args) {
      Dog dog = new Dog();
    //dog.age=10; 报错
      dog.name="Donald Trump";
      System.out.println(dog.name);
      dog.eat();
    }
}
  • 方法重写
class Dog extends Animal{
    public void eat(){
        System.out.println("狗具有吃的能力");
    }   
}
  • 初始化顺序


public class Animal {
    public int age=10;
    public Animal(){
        System.out.println("Animal类构造了");
        age=20;
    }
}
class Dog extends Animal{
    public Dog(){
        System.out.println("Dog类构造了");
    }   
}
public class helloworld {
    public static void main(String[] args) {
      Dog dog = new Dog();
      System.out.println("age = " +dog.age);
    }
}
  • final的使用


//final public class Animal 类不可被继承
public class Animal{
    final public int age=10;
    public String name;
    //final public void eat() 方法不可被继承
    public void eat(){
        final int i=999;
        //i=2; 变量i变为常量999
        System.out.println("动物具有吃的能力");
    }
    public Animal(){
        System.out.println("Animal类构造了");
        //age=20; 属性不可被修改
    }
}
class Dog extends Animal{
    public void eat(){
        System.out.println("狗具有吃的能力");
    }   
}
  • super的使用


public class Animal{
    public int age=10;
    public void eat(){
        System.out.println("动物具有吃的能力");
    }
}
class Dog extends Animal{
    int age=20;
    public void eat(){
        System.out.println("狗具有吃的能力");
    }  
    public Dog(){
      //super(); 默认调用,且必须为第一行
        eat();
        super.eat();
        System.out.println("super.age = "+super.age);
        System.out.println("age = "+age);
    }  
}
public class helloworld {
    public static void main(String[] args) {
      Dog dog = new Dog();
    }
}
  • Object类1


//public class Animal{ 
public class Animal extends Object{
    public int age=10;
}
class Dog extends Animal{
    int age=20;
}
public class helloworld {
    public static void main(String[] args) {
      Dog dog = new Dog();
      System.out.println(dog);
    }
}
//public class Animal{  等效语句
public class Animal extends Object{
    public int age=10;
}
class Dog extends Animal{
    int age=20;
    public String toString() {
        return "Dog [age=" + age + "]";
    }  
}
public class helloworld {
    public static void main(String[] args) {
      Dog dog = new Dog();
      System.out.println(dog);
    }
}
  • Object类2


public class Dog{ 
    public int age=10;
}
public class helloworld {
    public static void main(String[] args) {
      Dog dog1 = new Dog();
      Dog dog2 = new Dog();
    //if(dog1==dog2){ 等效语句
      if(dog1.equals(dog2)){
          System.out.println("两个对象是相同的");
      }else{
          System.out.println("两个对象是不同的");     
      }
    }
}
public class Dog{ 
    public int age=10;
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        //比较类对象
        if (getClass() != obj.getClass())
            return false;
        Dog other = (Dog) obj;
        //比较属性值
        if (age != other.age)
            return false;
        return true;
    }
}
public class helloworld {
    public static void main(String[] args) {
      Dog dog1 = new Dog();
      Dog dog2 = new Dog();
    //if(dog1==dog2){ 等效语句
      if(dog1.equals(dog2)){
          System.out.println("两个对象是相同的");
      }else{
          System.out.println("两个对象是不同的");     
      }
    }
}

九.多态

  • 多态
public class Animal {
    public void eat(){
        System.out.println("动物有吃东西的能力");
    }
}
public class Dog extends Animal {
    public void eat(){
        System.out.println("狗狗有吃东西的能力");
    }
    public void watchdoor(){
        System.out.println("狗狗有看门的能力");
    }
}
public class Cat extends Animal {
}
public class Initial {
    public static void main (String[]args){
        //引用多态
        Animal obj1=new Animal();//父类引用指向本类对象
        Animal obj2=new Dog();//父类引用指向子类对象
        Animal obj3=new Cat();
        //方法多态
        obj1.eat();
        obj2.eat();
        //obj2.watchdoor();报错
        obj3.eat();
    }
}
  • 引用类型转换
public class Initial {
    public static void main (String[]args){
        Animal animal=new Animal();
        Dog dog=new Dog();
        Cat cat=new Cat();
        
        animal=dog;//向上类型转换
        dog=(Dog)animal;//向下类型转换
        if(animal instanceof Cat){
            cat=(Cat)animal;
        }else{
            System.out.println("类型转换失败");
        }
    }
}
  • 抽象类
public abstract class Phone {
    public abstract void call();
    public abstract void message();
}
public class Telphone extends Phone {
    public void call() {
        System.out.println("小灵通通过键盘打电话");
    }
    public void message() {
        System.out.println("小灵通通过键盘发短信");
    }
}
public class Smartphone extends Phone {
    public void call() {
        System.out.println("智能机通过语音打电话");
    }
    public void message() {
        System.out.println("智能机通过语音发短信");
    }
}
        Phone phone1=new Telphone();
        Phone phone2=new Smartphone();
        phone1.call();
        phone1.message();
        phone2.call();
        phone2.message();
  • 接口
public interface Iplaygame {
    public void playgame();
}
public class Smartphone implements Iplaygame {
    public void playgame() {
        System.out.println("智能机具有玩游戏的功能");
    }
}
public class PSP implements Iplaygame {
    public void playgame() {
        System.out.println("PSP具有玩游戏的功能");
    }
}
        Iplaygame ip1=new Smartphone();
        Iplaygame ip2=new PSP();
        ip1.playgame();
        ip2.playgame();
  • UML使用

设计UML图

生成代码

十.异常处理

  • 异常简介
  • try..catch..finally
import java.util.*;

public class exception {
    public static void main(String[] args){
        try{
            Scanner input = new Scanner(System.in);
            System.out.print("请输入第一个数:");
            int a=input.nextInt();
            System.out.print("请输入第二个数:");
            int b=input.nextInt();
            System.out.println("两数相除的结果为:"+a/b);
        }catch(InputMismatchException e){
            System.out.println("你应该输入整数!!");
        }catch(ArithmeticException e){
            System.out.println("分母不能为0!!");
        }catch(Exception e){
            System.out.println("我是不知名异常");
        }finally{
            System.out.println("哈哈哈");
        }
    }
}
public class TryCatchTest {
    public static void main(String[] args) {
        TryCatchTest a=new TryCatchTest();
        int result=a.test();
        System.out.println("test()方法执行完毕,返回值:"+result);
        int result2=a.test2();
        System.out.println("test2()方法执行完毕,返回值:"+result2);
        int result3=a.test3();
        System.out.println("test3()方法执行完毕,返回值:"+result3);
    }
    /**
     * 捕获异常,打印输出“循环出现异常!!",返回-1
     * 否则,返回result
     * @return
     */
    public int test(){
        int divider=10;
        int result=100;
        try{
            while(divider>-1){
                divider--;
                result+=100/divider;
            }
            return result;
        }catch(Exception e){
            e.printStackTrace();
            System.out.println("循环出现异常!!");
            return -1;
        }
    }
    /**
     * 捕获异常,打印输出“循环出现异常!!",返回result=999
     * 否则,返回result
     * @return
     */
    public int test2(){
        int divider=10;
        int result=100;
        try{
            while(divider>-1){
                divider--;
                result+=100/divider;
            }
            return result;
        }catch(Exception e){
            e.printStackTrace();
            System.out.println("循环出现异常!!");
            return result=999;
        }finally{
            System.out.println("我是finally!!");
        }
    }
    /**
     * 捕获异常,打印输出“循环出现异常!!"
     * 返回1234
     * @return
     */
    public int test3(){
        int divider=10;
        int result=100;
        try{
            while(divider>-1){
                divider--;
                result+=100/divider;
            }
        }catch(Exception e){
            e.printStackTrace();
            System.out.println("循环出现异常!!");
        }finally{
            System.out.println("result值为:"+result);
        }
        return 1234;
    }
}
  • 异常抛出及自定义异常
public class DrunkException extends Exception {
    public DrunkException(String message){
        super(message);
    }
}
  • 异常链
public class ChainTest {
    /**
     *test1()抛出“喝车别开酒”异常
     *test2()调用test1(),捕获异常,并包装成运行时异常抛出
     *main方法调用test2(),捕获异常
     */
    public static void main(String[] args) {
        ChainTest ct=new ChainTest();
        try{
            ct.test2();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public void test1() throws DrunkException{
        throw new DrunkException("喝车别开酒");
    }
    public void test2(){
        try{
            test1();
        }catch(DrunkException e){
            RuntimeException x=new RuntimeException(e);
            throw x;
        }
    }
}

十一.字符串

  • 什么是字符串
        String hobby = "追剧";
        String url = "https://www.iqiyi.com/";        
        System.out.println("hobby:" + hobby);
        System.out.println("url:" + url);
  • 不变性
        String s1 = "孙诗语";
        String s2 = "孙诗语";
        String s3 = "I love " + s1;
        String s4 = "I love " + s1;
        System.out.println("s1和s2内存地址相同吗?" + (s1 == s2));
        System.out.println("s1和s3内存地址相同吗?" + (s1 == s3));
        System.out.println("s3和s4内存地址相同吗?" + (s3 == s4));
  • String 类的常用方法 Ⅰ
public class test {
    public static void main(String[] args) {
        // Java文件名
        String file = "Hello.World.java"; 
        // 邮箱
        String email = "2041103554@qq.com";
        //获取文件名中最后一次出现"."号的位置
        int index = file.lastIndexOf('.');
        
        // 获取文件的后缀
        String hz = file.substring(index+1,file.length());
        
        // 判断必须包含"."号,且不能出现在首位,同时后缀名为"java"
        if (index != -1 && index != 0 && hz.equals("java")) {
            System.out.println("Java文件名正确");
        } else {
            System.out.println("Java文件名无效");
        }

        // 获取邮箱中"@"符号的位置
        int index2 = email.indexOf('@');
        
        // 获取邮箱中"."号的位置
        int index3 = email.indexOf('.');
        
        // 判断必须包含"@"符号,且"@"必须在"."之前
        if (index2 != -1 && index2 < index3) {
            System.out.println("邮箱格式正确");
        } else {
            System.out.println("邮箱格式无效");
        }
    }
}

十二.常用类

  • 包装类
        int score1 = 86; 
        Integer score2=new Integer(score1);
        double score3=score2.doubleValue();
        float score4=score2.floatValue();
        int score5 =score2.intValue();

        System.out.println("Integer包装类:" + score2);
        System.out.println("double类型:" + score3);
        System.out.println("float类型:" + score4);
        System.out.println("int类型:" + score5);
  • 基本类型和包装类之间的转换
        double a = 91.5;
        Double b = new Double(a);   
        System.out.println("装箱后的结果为:" + b );
        Double d = new Double(87.0);
        double e = d.doubleValue();                
        System.out.println("拆箱后的结果为:" + e );
  • 基本类型和字符串之间的转换
        double m = 100.0;
        //将基本类型转换为字符串
        String str1 = Double.toString(m);
        System.out.println("m 转换为String型后与整数20的求和结果为: "+(str1+20));
        String str = "100.0";
        // 将字符串转换为基本类型
        double a = Double.parseDouble(str)                    ;
        System.out.println("str 转换为double型后与整数20的求和结果为: "+(a+20));
  • 使用 Date 和 SimpleDateFormat 类表示时间
import java.text.*;
import java.util.*;

public class HelloWorld {
    public static void main(String[] args) throws ParseException {
        SimpleDateFormat a = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        Date x =new Date();
        System.out.println(a.format(x));
        
        SimpleDateFormat b = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String d = "2020-7-1 21:05:36";
        Date y = b.parse(d);
        System.out.println(b.format(y));
        System.out.println(y);
    }
}
  • Calendar 类的应用
        Calendar c = Calendar.getInstance();
        Date date = c.getTime();
        SimpleDateFormat x = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前时间:" + x.format(date));
  • 使用 Math 类操作数据
        double[] nums = new double[5];
        // 为数组随机赋值
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Math.random();;
        }
        // 使用foreach循环输出数组中的元素
        for (double num:nums) {
            System.out.println(num + " ");
        }

十三.集合框架(上)

  • 集合框架概述
  • Collection 接口 & List 接口
  • 学生选课---创建学生类和课程类
package com.Du1in9.collection;
import java.util.*;
/*
 * 学生类
 */
public class Student {
    public String id;
    public String name;
    public Set Courses;
    public Student(String id,String name){
        this.id=id;
        this.name=name;
        this.Courses=new HashSet();
    }
} 
package com.Du1in9.collection;
/*
 * 课程类
 */
public class Course {
    public String id;
    public String name;
    public Course(String id,String name){
        this.id=id;
        this.name=name;
    }
}
  • 学生选课---课程增加
package com.Du1in9.collection;
import java.awt.*;
import java.util.*;
import java.util.List;

public class ListTest {
    /*
     * 用于存放课程的List
     */
    public List coursesSelect;
    public ListTest(){
        this.coursesSelect=new ArrayList();
    }
    /*
     * 用于往coursesSelect添加备选课程
     */
    public void Add(){
        //方法一
        Course c=new Course("1","数据结构");
        coursesSelect.add(c);
        Course temp=(Course)coursesSelect.get(0);
        System.out.println("添加了课程: "+temp.id+" : "+temp.name);
        Course c2=new Course("2","C语言");
        //插入到下标0位置,"数据结构"往后移
        coursesSelect.add(0,c2);
        Course temp2=(Course)coursesSelect.get(0);
        System.out.println("添加了课程: "+temp2.id+" : "+temp2.name);
        Course c3=new Course("3","Python");
        //插入到下标2位置,大于2会数组越界
        coursesSelect.add(2,c3);
        Course temp3=(Course)coursesSelect.get(2);
        System.out.println("添加了课程: "+temp3.id+" : "+temp3.name);
        
        //方法二
        Course[] c4={new Course("4","汇编语言"),new Course("5","离散数学")};
        coursesSelect.addAll(Arrays.asList(c4));
        Course temp4=(Course)coursesSelect.get(3);
        Course temp5=(Course)coursesSelect.get(4);
        System.out.println("添加了两门课程: "+temp4.id+" : "+temp4.name+" "+temp5.id+" : "+temp5.name);
        Course[] c5={new Course("6","高等数学"),new Course("7","大学英语")};
        //插入到下标3,4位置,"汇编语言","离散数学"往后移
        coursesSelect.addAll(3,Arrays.asList(c5));
        Course temp6=(Course)coursesSelect.get(3);
        Course temp7=(Course)coursesSelect.get(4);
        System.out.println("添加了两门课程: "+temp6.id+" : "+temp6.name+" "+temp7.id+" : "+temp7.name);    
    }
    public static void main(String[]args){
        ListTest x=new ListTest();
        x.Add();
    }
}
  • 学生选课---课程查询
    public void Get(){
        int n=coursesSelect.size();
        System.out.println("有如下课程待选:");
        for(int i=0;i<n;i++){
            Course c=(Course)coursesSelect.get(i);
            System.out.println("课程:"+c.id+":"+c.name);
        }
    }
    /*
     * 通过迭代器遍历List
     */
    public void Iterator(){
        Iterator it=coursesSelect.iterator();
        System.out.println("通过迭代器访问:");
        while(it.hasNext()){
            Course c=(Course)it.next();
            System.out.println("课程:"+c.id+":"+c.name);
        }
    }
    /*
     * 通过Foreach方法遍历List
     */
    public void ForEach(){
        System.out.println("通过Foreach方法访问:");
        for(Object obj:coursesSelect){
            Course c=(Course)obj;
            System.out.println("课程:"+c.id+":"+c.name);
        }
    }
  • 学生选课---课程修改
    public void Modify(){
        coursesSelect.set(0, new Course("8","毛概"));
    }
  • 学生选课---课程删除
    public void Remove1(){
        Course c=(Course)coursesSelect.get(0);
        coursesSelect.remove(c);
    }
    public void Remove2(){
        coursesSelect.remove(0);
    }
    public void RemoveAll(){
        Course[] c={(Course)coursesSelect.get(3),(Course)coursesSelect.get(4)};
        coursesSelect.removeAll(Arrays.asList(c));
    }
  • 应用泛型管理课程 Ⅰ
package com.Du1in9.collection;
import java.util.*;

public class Generic {
    /*
     * 用于存放课程的List
     */
    public List<Course> course;
    public Generic(){
        this.course=new ArrayList<Course> ();
    }
    public void Add(){
        Course c=new Course("1","大学语文");
        course.add(c);
        Course c2=new Course("2","Java基础");
        course.add(c2);
    }
    public void ForEach(){
        for(Course obj:course){
            System.out.println("课程:"+obj.id+":"+obj.name);
        }
    }
    public static void main(String[] args) {
        Generic c=new Generic();
        c.Add();
        c.ForEach();
    }
}
  • 应用泛型管理课程 Ⅱ
public class Course {
    public String id;
    public String name;
    public Course(String id,String name){
        this.id=id;
        this.name=name;
    }
    public Course(){
        
    }
}
public class ChildCourse extends Course {

}
    /*
     * 添加泛型子类型的对象实例
     */
    public void Child(){
        ChildCourse cc=new ChildCourse();
        cc.id="3";
        cc.name="我是子类型的课程对象实例";
        course.add(cc);
    }
    /*
     * 泛型不能使用基本类型
     */
    public void BasicType(){
            List<Integer> list=new ArrayList<Integer> ();
            list.add(1);
            System.out.println("基本类型必须使用包装类作为泛型:"+list.get(0));
    }
  • 通过 Set 集合管理课程

Student.java

    public Set <Course>Courses;
    ...
    this.Courses=new HashSet<Course>();

SetTest.java

package com.Du1in9.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class SetTest {

    public List<Course> coursesToSelect;
    
    public SetTest() {
        coursesToSelect = new ArrayList<Course>();
    }
    
    public void testAdd() {
        
        // 创建一个课程对象,并通过调用add方法,添加到备选课程List中
        Course cr1 = new Course("1", "数据结构");
        coursesToSelect.add(cr1);
        Course temp = (Course) coursesToSelect.get(0);

        Course cr2 = new Course("2", "C语言");
        coursesToSelect.add(0, cr2);
        Course temp2 = (Course) coursesToSelect.get(0);

        Course[] course = { new Course("3", "离散数学"), new Course("4", "汇编语言") };
        coursesToSelect.addAll(Arrays.asList(course));
        Course temp3 = (Course) coursesToSelect.get(2);
        Course temp4 = (Course) coursesToSelect.get(3);

        Course[] course2 = { new Course("5", "高等数学"), new Course("6", "大学英语") };
        coursesToSelect.addAll(2, Arrays.asList(course2));
        Course temp5 = (Course) coursesToSelect.get(2);
        Course temp6 = (Course) coursesToSelect.get(3);
    }

    public void testForEach() {
        System.out.println("有如下课程待选(通过for each访问):");
        for (Object obj : coursesToSelect) {
            Course cr = (Course) obj;
            System.out.println("课程:" + cr.id + ":" + cr.name);
        }
    }

    public static void main(String[] args) {
        SetTest st = new SetTest();
        st.testAdd();
        st.testForEach();
        Student student = new Student("1", "小明");
        System.out.println("欢迎学生:" + student.name + "选课!");
        
        // 创建一个Scanner对象,用来接收从键盘输入的课程ID
        Scanner console = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入课程ID");
            String courseId = console.next();
            for (Course cr : st.coursesToSelect) {
                if (cr.id.equals(courseId)) {
                    //Set中添加某个对象,无论添加多少次, 最终只会保留第一次添加的那一个
                    student.Courses.add(cr);
                }
            }
        }
        st.testForEachForSet(student);
    }

    public void testForEachForSet(Student student) {
        System.out.println("共选择了:" + student.Courses.size() + "门课程!");
        // 由打印输出可知Set存放无序
        for (Course cr : student.Courses) {
            System.out.println("选择了课程:" + cr.id + ":" + cr.name);
        }
    }
}

十四.集合框架(中)

  • Map & HashMap 简介
  • 使用 Map 添加学生

MapTest.java

package com.Du1in9.collection;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;

public class MapTest {

    public Map<String, Student> students;

    public MapTest() {
        this.students = new HashMap<String, Student>();
    }
    
    //输入学生ID,若未被占用则输入姓名,创建新学生对象并添加到students中
    public void testPut() {
        // 创建一个Scanner对象,用来获取输入的学生ID和姓名
        Scanner console = new Scanner(System.in);
        int i = 0;
        while (i < 3) {
            System.out.println("请输入学生ID:");
            String ID = console.next();
            Student st = students.get(ID);
            if (st == null) {
                System.out.println("请输入学生姓名:");
                String name = console.next();
                Student newStudent = new Student(ID, name);
                
                // 通过调用students的put方法,添加ID-学生映射
                students.put(ID, newStudent);
                System.out.println("成功添加学生:" + students.get(ID).name);
                i++;
            } else {
                System.out.println("该学生ID已被占用!");
                continue;
            }
        }
    }

    // 1)通过keySet方法来遍历Map
    public void testKeySet() {
        // 返回Map中的所有键
        Set<String> keySet = students.keySet();
        System.out.println("总共有:" + students.size() + "个学生!");
        for (String stuId : keySet) {
            Student st = students.get(stuId);
            if (st != null)
                System.out.println("学生:" + st.name);
        }
    }

    public static void main(String[] args) {
        MapTest mt = new MapTest();
        mt.testPut();
        mt.testKeySet();
    }
    
}
  • 删除 Map 中的学生

MapTest.java

    // 2)通过entrySet方法来遍历Map
    public void testEntrySet() {
        // 返回Map中的所有键值对
        Set<Entry<String, Student>> entrySet = students.entrySet();
        for (Entry<String, Student> entry : entrySet) {
            System.out.println("取得键:" + entry.getKey());
            System.out.println("对应的值为:" + entry.getValue().name);
        }
    }

    public void testRemove() {
        Scanner console = new Scanner(System.in);
        while (true) {
            System.out.println("请输入要删除的学生ID!");
            String ID = console.next();
            Student st = students.get(ID);
            if (st == null) {
                System.out.println("该ID不存在!");
                continue;
            }
            students.remove(ID);
            System.out.println("成功删除学生:" + st.name);
            break;
        }
    }
  • 修改 Map 中的学生

MapTest.java

    public void testModify() {
        System.out.println("请输入要修改的学生ID:");
        Scanner console = new Scanner(System.in);
        while (true) {
            String stuID = console.next();
            Student student = students.get(stuID);
            if (student == null) {
                System.out.println("该ID不存在!请重新输入!");
                continue;
            }
            System.out.println("当前该学生ID,所对应的学生为:" + student.name);
            System.out.println("请输入新的学生姓名:");
            String name = console.next();
            Student newStudent = new Student(stuID, name);
            students.put(stuID, newStudent);
            System.out.println("修改成功!");
            break;
        }
    }

十五.集合框架(下)

  • 判断 List 中课程是否存在

Course.java

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof Course))
            return false;
        Course other = (Course) obj;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        return true;
    }

SetTest.java

package com.Du1in9.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class SetTest {

    public List<Course> coursesToSelect;
    private Scanner console;
    public Student student;

    public SetTest() {
        coursesToSelect = new ArrayList<Course>();
        console = new Scanner(System.in);
    }
    public void testAdd() {
    ...
    }
    public void testForEach() {
    ...
    }

    // 测试List的contains方法
    public void testListContains() {
        // 取得备选课程序列的第0个元素
        Course course = coursesToSelect.get(0);
        System.out.println("取得课程:" + course.name);
        System.out.println("备选课程中是否包含课程:" + course.name + ", " + coursesToSelect.contains(course));

        Course course2 = new Course();
        System.out.println("请输入课程名称:");
        String name = console.next();
        course2.name = name;
        System.out.println("新创建课程:" + course2.name);
        System.out.println("备选课程中是否包含课程:" + course2.name + ", " + coursesToSelect.contains(course2));
        System.out.println("课程:" + course2.name + "的索引位置为:" + coursesToSelect.indexOf(course2));
    }
    
    public static void main(String[] args) {
        SetTest st = new SetTest();
        st.testAdd();
        st.testListContains();
    }

}
  • 判断 Set 中课程是否存在

Course.java

    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

SetTest.java

    // 测试Set的contains方法
    public void testSetContains() {
        System.out.println("请输入学生已选的课程名称:");
        String name = console.next();
        Course course2 = new Course();
        course2.name = name;
        System.out.println("新创建课程:" + course2.name);
        System.out.println("备选课程中是否包含课程:" + course2.name + ", " + student.Courses.contains(course2));
    }

    // 创建学生对象并选课
    public void createStudentAndSelectCours() {
        student = new Student("1", "小明");
        System.out.println("欢迎学生:" + student.name + "选课!");
        Scanner console = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入课程ID");
            String courseId = console.next();
            for (Course cr : coursesToSelect) {
                if(cr.id.equals(courseId)) {
                    student.Courses.add(cr);
                }
            }
        }
    }

    ...

        st.testAdd();
        st.testForEach();
        st.createStudentAndSelectCours();
        st.testSetContains();
  • 获取 List 中课程的位置
        if (coursesToSelect.contains(course2))
            System.out.println(coursesToSelect.indexOf(course2));
  • 判断 Map 中是否包含指定的 key 和 value

MapTest.java

    public void testContainsKeyOrValue() {
        // Key值
        System.out.println("请输入要查询的学生ID:");
        Scanner console = new Scanner(System.in);
        String id = console.next();
        System.out.println("您输入的学生ID为:" + id);
        if (students.containsKey(id))
            System.out.println("在学生映射表中,确实包含学生:" + students.get(id).name);
        // Value值
        System.out.println("请输入要查询的学生姓名:");
        String name = console.next();
        if (students.containsValue(new Student(null,name)))
            System.out.println("在学生映射表中,确实包含学生:" + name);
        else
            System.out.println("在学生映射表中不存在该学生!");
    }

Student.java

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof Student))
            return false;
        Student other = (Student) obj;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        return true;
    }
  • 应用 Collections.sort() 实现 List 排序

CollectionsTest.java

package com.Du1in9.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class CollectionsTest {

    /**
     * 1)通过Collections.sort()方法,对Integer泛型的List进行排序;
     */
    public void testSort1() {
        
        // 泛型不能为基本类型int,所以用包装类Integer
        List<Integer> integerList = new ArrayList<Integer>();
        // 插入十个100以内的不重复的随机整数
        Random random = new Random();
        Integer k;
        for (int i = 0; i < 10; i++) {
            do {
                k = random.nextInt(100);
            } while (integerList.contains(k));
            integerList.add(k);
            System.out.println("成功添加整数:" + k);
        }
        System.out.println("-------------排序前--------------");
        for (Integer integer : integerList) {
            System.out.println("元素:" + integer);
        }
        Collections.sort(integerList);
        System.out.println("----------------排序后-------------------");
        for (Integer integer : integerList) {
            System.out.println("元素:" + integer);
        }
    }

    public static void main(String[] args) {
        CollectionsTest ct = new CollectionsTest();
        ct.testSort1();
    }

}
    /**
     * 2)对String泛型的List进行排序;
     * 
     */
    public void testSort2() {
        List<String> stringList = new ArrayList<String>();
        stringList.add("microsoft");
        stringList.add("9oogle");
        stringList.add("1enovo");
        stringList.add("Huawei");
        System.out.println("------------排序前-------------");
        for (String string : stringList) {
            System.out.println("元素:" + string);
        }
        // 排列顺序:数字 -> 大写字母 -> 小写字母
        Collections.sort(stringList);
        System.out.println("------------排序后-------------");
        for (String string : stringList) {
            System.out.println("元素:" + string);
        }
    }
    /**
     * 练习:每条字符串长度10以内且不可重复,调用sort方法排序再输出
     */
    public void testSort() {
        List<String> strtinglist = new ArrayList<String>();
        Random random = new Random();
        Integer k;
        String str = "abcedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        for (int i = 0; i < 10; i++) {
            StringBuffer newstring = new StringBuffer();
            do {
                k = random.nextInt(10);
                for (int j = 0; j < k+1; j++) {
                    int x = random.nextInt(str.length());
                    newstring.append(str.charAt(x));
                    }
                }while(strtinglist.contains(newstring));
            System.out.println("添加字符串:"+"'"+newstring.toString()+"'");
            strtinglist.add(newstring.toString());
            }
        System.out.println("----------排序前---------");
        for (String string : strtinglist) {
            System.out.println("元素"+string);
            }
        Collections.sort(strtinglist);
        System.out.println("----------排序后---------");
        for (String string : strtinglist) {
            System.out.println("元素"+string);
            }
        }
  • Comparable & Comparator 简介

1)默认的比较规则

2)临时的比较规则

  • 实现学生序列排序

Student.java

public class Student implements Comparable<Student> {

    ...

    //@Override
    public int compareTo(Student o) {
        return this.id.compareTo(o.id);
    }
}

StudentComparator.java

package com.Du1in9.collection;

import java.util.Comparator;

public class StudentComparator implements Comparator<Student> {
    //@Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}

CollectionsTest.java

    /**
     * 3)对其他类型泛型的List进行排序,以Student为例。
     */
    public void testSort3() {
        List<Student> studentList = new ArrayList<Student>();
        Random random = new Random();
        studentList.add(new Student(random.nextInt(1000) + "", "Mike"));
        studentList.add(new Student(random.nextInt(1000) + "", "Angela"));
        studentList.add(new Student(random.nextInt(1000) + "", "Lucy"));
        studentList.add(new Student(10000 + "", "Beyonce"));
        System.out.println("--------------排序前--------------------");
        for (Student student : studentList) {
            System.out.println("学生:" + student.id + ":" + student.name);
        }
        Collections.sort(studentList);
        System.out.println("--------------按照id排序后--------------");
        for (Student student : studentList) {
            System.out.println("学生:" + student.id + ":" + student.name);
        }
        Collections.sort(studentList, new StudentComparator());
        System.out.println("--------------按照姓名排序后-------------");
        for (Student student : studentList) {
            System.out.println("学生:" + student.id + ":" + student.name);
        }
    }

十六.简易扑克牌游戏

PlayTest.java

package com.Du1in9;

import java.util.*;

public class PlayTest {

    List<Pai> list = new ArrayList<Pai>();
    List<Person> persons = new ArrayList<Person>();
    Map<Short,String> huaMap=new HashMap<Short, String>(){
        {
            put((short)0,"红桃");
            put((short)1,"黑桃");
            put((short)2,"方片");
            put((short)3,"梅花");
        }
    };
    /**
     * 1)洗牌
     */
    public void init(){
        System.out.println("洗牌ing...");
        // 清空牌库
        list=new ArrayList<Pai>();
        // 创建13*4的对象,使用set随机排列
        Set<Pai> pais=new HashSet<Pai>();
        for(int i=1; i<14; i++){
            for (short j=0; j<4; j++) {
                Pai pai=new Pai();
                pai.setHua(j);
                pai.setNumber(i);
                pais.add(pai);
            }
        }
        // 把牌放入牌库中
        list.addAll(pais);
    }
    /**
     * 2)创建玩家
     */
    public void initPerson(){
        System.out.println("初始化ing...");
        Person p1 = new Person();
        p1.setId(1);
        p1.setName("玩家一");
        persons.add(p1);
        Person p2 = new Person();
        p2.setId(2);
        p2.setName("玩家二");
        persons.add(p2);
    }
    /**
     * 3)发牌
     */
    public List<HandPai> fapai(){
        System.out.println("----------开始发牌-----------");
        if(list.size() < 4){
            this.init();
        }
        List<HandPai> handList=new ArrayList<HandPai>();
        for(int i=4; i>0; i--){
            HandPai handPai=new HandPai();
            Pai pai=list.get(i-1);
            handPai.setHua(pai.getHua());
            handPai.setNumber(pai.getNumber());
            if(i%2==0){
                handPai.setName(persons.get(0).getName());
            }else{
                handPai.setName(persons.get(1).getName());
            }
            handList.add(handPai);

            list.remove(i-1);
            System.out.println(handPai.getName()+": "+huaMap.get(handPai.getHua())+handPai.getNumber());
        }
        return handList;
    }

    /**
     * 4)比较大小
     */
    public void bijiao(List<HandPai> handPais){
        Collections.sort(handPais,new PaiCompara());
        System.out.println("----------游戏结果-----------");
        System.out.println("获胜者为:"+handPais.get(3).getName());
        System.out.println("最大点数为: "+handPais.get(3).getNumber() +", 花色为: "+huaMap.get(handPais.get(3).getHua()));
        System.out.println("-----------------------------");
    }

    public static void main(String[] args) {
        System.out.println("----------------------------");
        System.out.println("输入1开始游戏:");
        Scanner scanner=new Scanner(System.in);
        int cmd=scanner.nextInt();
        if(cmd == 1){
            PlayTest  playTest=new PlayTest();
            playTest.init();
            playTest.initPerson();
            do {
                List<HandPai> handPaiList=playTest.fapai();
                playTest.bijiao(handPaiList);
                System.out.println("输入2继续发牌:");
                cmd=scanner.nextInt();
            }while (cmd == 2);
        }
    }

    /**
     * 手牌对象
     */
    class HandPai implements Comparable<HandPai>{
        //玩家名称
        private String name;
        //扑克牌花色,0-红桃 1-黑桃 2-方片 3-梅花
        private Short hua;
        //牌号 1-13
        private int number;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Short getHua() {
            return hua;
        }
        public void setHua(Short hua) {
            this.hua = hua;
        }
        public int getNumber() {
            return number;
        }
        public void setNumber(int number) {
            this.number = number;
        }
        public int compareTo(HandPai o) {
            return 0;
        }
    }
    /**
     * 比较规则
     */
    class PaiCompara implements Comparator<HandPai>{
        public int compare(HandPai o1, HandPai o2) {
            if(o1.getNumber()>o2.getNumber()){
                return 1;
            }else if(o1.getNumber()<o2.getNumber()){
                return -1;
            }else{
                if(o1.getHua()>o2.getHua()){
                    return 1;
                }else if(o1.getHua()<o2.getHua()){
                    return -1;
                }
            }
            return 0;
        }
    }

    /**
     * 扑克牌对象
     */
    public class Pai {
        //扑克牌花色 0-红桃 1-黑桃 2-方片 3-梅花
        private Short hua;
        //牌号 1-13
        private int number;
        public Short getHua() {
            return hua;
        }
        public void setHua(Short hua) {
            this.hua = hua;
        }
        public int getNumber() {
            return number;
        }
        public void setNumber(int number) {
            this.number = number;
        }
    }
    /**
     * 创建打牌玩家
     */
    public class Person {

        private int id;
        private String name;
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,527评论 5 470
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,314评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,535评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,006评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,961评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,220评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,664评论 3 392
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,351评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,481评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,397评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,443评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,123评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,713评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,801评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,010评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,494评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,075评论 2 341