首页 > 编程语言 >day0722~day0726Java基础

day0722~day0726Java基础

时间:2024-07-27 13:54:56浏览次数:10  
标签:String day0726Java int 基础 System day0722 println public out

目录

异常

编译异常(受检异常)   

运行异常(非受检异常)

异常处理

捕获异常:try…catch

 try... catch 支持多分支catch 语句书写

try ...catch... finally语句 

throws/throw 关键字

 自定义异常

 线程

线程调度

线程的优先级

创建线程

1. Thread类 线程类

2. Runnable 接口

3.匿名内部类

线程安全

1. 锁对象 

2.给当前方法加锁

等待与唤醒机制

wait     notify    notifyAll

常用类

Math

Calendar  日历类

Time 

LocalDate

LocalTime

LocalDateTime

数组

Arrays.sort();        排序从小到大

Arrays.binarySearch()        查找数组是排好序的

Arrays.copyOf(数组,长度)        复制数组

Arrays.copyOfRange(数组,from,to)        左闭右开

字符串

String

StringBuffer

String、StringBuffer、StringBuilder 

Java 中==和 equals 的区别

集合

有序集合List

ArrayList

LinkedList

无序集合set

HashSet

TreeSet

LinkedHashSet

迭代器Iterator和foreach

泛型

异常

编译异常(受检异常)   

这类异常通常使用 try-catch 块来捕获并处理异常,或者在方法声明中使用 throws 子句声明方法可能抛出的异常。

运行异常(非受检异常)

 这些异常在编译时不强制要求处理,通常是由程序中的错误引起的,例如 NullPointerException、ArrayIndexOutOfBoundsException 等,这类异常可以选择处理,但并非强制要求。

 public static void main(String[] args) {
        // 受检异常
        // 编译时异常 在写代码的时候出现的错误 编译器看不下去了 直接不允许你编译
//        System.out.println(a);



        // 非受检异常
        // 运行时异常 在代码执行的时候出现的意想不到的问题
//        Exception in thread "main"
//        java.lang.ArithmeticException: / by zero
//        at com.haogu.Java01.main(Java01.java:11)

//        error 错误  报错之后的信息

        int num1 = 10;
        int num2 = 0;
      System.out.println(num1 / num2);
    }

Throwable 是所有 Java 程序中错误处理的父类,有两种类:Error 和 Exception。

Error:表示由 JVM 所侦测到的无法预期的错误,由于这是属于 JVM 层次的严重错误,导致 JVM 无法继续执行,因此,这是不可捕捉到的,无法采取任何恢复的操作,顶多只能显示错误信息。

Exception:表示可恢复的例外,这是可捕捉到的。

异常处理

捕获异常:try…catch

 异常捕获 
 try{ 
 尝试要执行的代码 
 有可能出错的代码 
 }catch (异常类型 异常名称){ 
 处理捕获到的异常 
 }
    public static void main(String[] args) {

        try {
            int num1 = 10;
            int num2 = 0;
            System.out.println(num1 / num2);

            System.out.println("执行了哈哈哈!!!");
        }catch (Exception e){
            System.out.println(e);
            System.out.println("错误执行,仔细检查一下");
            e.printStackTrace(); // 打印异常
        }
    }

 try... catch 支持多分支catch 语句书写

try{
   // 程序代码
}catch(异常类型1 异常的变量名1){
  // 程序代码
}catch(异常类型2 异常的变量名2){
  // 程序代码
}catch(异常类型3 异常的变量名3){
  // 程序代码
}

try ...catch... finally语句 

 public static void main(String[] args) {
        //try 不执行 finally 也不执行
//        if (2==2){
//            return;
//        }
        try {
            int num1=10;
            int num2=0;
            //跳出来main方法 但是finally还是执行
            if (2==2){
                return;
            }
            System.out.println(num1/num2);
        }catch (Exception e){
            System.out.println("捕获到了");
        }finally {
            //只要try 执行 finally 必执行
            //无论是否 出现异常 finally 总会执行
            System.out.println("你会执行吗!!!!");
        }
    }

throws/throw 关键字

在Java中, throw 和 throws 关键字是用于处理异常的。

throw 关键字用于在代码中抛出异常,而 throws 关键字用于在方法声明中指定可能会抛出的异常类型。

修饰符 返回值类型 方法名(参数) throws 异常类名1,异常类名2…{   }    

throw new 异常类名(参数);

public class Utils {
    public static String Week(int week) throws Exception{
        if(week == 1){
            return "星期一";
        }else if(week == 2){
            return "星期二";
        }else if(week == 3){
            return "星期三";
        }else if(week == 4){
            return "星期四";
        }else if(week == 5){
            return "星期五";
        }else if(week == 6){
            return "星期六";
        }else if(week == 7){
            return "星期七";
        }
//        手动抛出异常
        throw new Exception("有异常!!!");


    }


    public static String Week2(int week) throws Exception{
        if(week < 1 || week > 7){
            throw new Exception("星期数错误");
        }
        String [] weeks = {"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
        return weeks[week - 1];
    }

    public static String Week3(int week) throws WeekOutOfBoundsException{
        if(week < 1 || week > 7){
            throw new WeekOutOfBoundsException("星期数错误");
        }
        String [] weeks = {"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
        return weeks[week - 1];
    }

    public static int ress(int num1,int num2) throws ArithmeticException{
        return  num1 / num2;
    }
}

 自定义异常

public class WeekOutOfBoundsException extends RuntimeException {
    public WeekOutOfBoundsException(){

    }

    public WeekOutOfBoundsException(String mess){
        super(mess);
    }

}

 线程

并行(parallel):指两个或多个事件在同一时刻发生(同时发生)

并发(concurrency):指两个或多个事件在同一个时间段内发生。

线程调度

分时调度

抢占式调度

Thread currentThread() :返回对当前正在执行的线程对象的引用。

getPriority() :返回线程优先级

setPriority(int newPriority) :改变线程的优先级

getName() :获取当前线程名称。

线程的优先级

Priority() 通过set/get()方法进行设置与查看

线程的优先级默认 5+

优先级高的不代表一定能抢占到

 public static void main(String[] args) {
        Thread02 th01 = new Thread02("线程1");
        Thread02 th02 = new Thread02("线程2");
//        线程的优先级默认 5+
//        IllegalArgument  Exception
//        非法论据  非法参数
//        优先级最大 10  最小1
        // 线程资源抢占
        // 级别高不代表100%能抢占到
        th01.setPriority(Thread.MAX_PRIORITY);
        th02.setPriority(Thread.MIN_PRIORITY);
        th01.start();
        th02.start();
        System.out.println(Thread.currentThread().getName()+"************************"+
                Thread.currentThread().getPriority());

    }
public class Thread02 extends Thread{
    public Thread02() {
    }

    public Thread02(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
//            sleep 当前线程强制休息  1000ms = 1s
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()
                    +"************************"+
                    i);

        }
    }
}

创建线程

1. Thread类 线程类

public static void main(String[] args) {
//        获取当前的线程名称
        System.out.println(Thread.currentThread().getName());

        Thread01 th01 = new Thread01("线程1");
        Thread01 th02 = new Thread01("线程2");

        th01.start();
        th02.start();
    }
public class Thread01 extends Thread{
    public Thread01() {
    }

    public Thread01(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread()
                    .getName()+"***************"+i);
        }
    }
}

2. Runnable 接口

public static void main(String[] args) {
//        任务 需要执行的任务
        Runnable01 ra01 = new Runnable01();
//        Thread 类 来创建线程 参数 任务 和 名称
        Thread th01 = new Thread(ra01,"线程一");
        Thread th02 = new Thread(ra01,"线程二");

        th01.start();
        th02.start();

    }
public class Runnable01 implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread()
                    .getName()+"---------------"+i);
        }
    }
}

3.匿名内部类

 public static void main(String[] args) {

        new Thread("线程1..+"){
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println(Thread.currentThread().getName()+i);
                }
            }
        }.start();

        new Thread("线程2..+"){
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println(Thread.currentThread().getName()+i);
                }
            }
        }.start();
    }

线程安全

1. 锁对象 

这个对象是谁都行 只要是一个唯一的内容

​
public class Ticket02 implements Runnable{
    private int ticket = 100;
    Object obj = new Object();

    @Override
    public void run() {
//        锁对象  这个对象是谁都行 只要是一个唯一的内容
            while (true){
                synchronized (obj){
                    if(ticket < 1 ){
                        System.out.println("卖完了");
                        break;
                    }else {
                        System.out.println("当前在卖第"+ticket+"张票"+"**********"+Thread.currentThread().getName());
                         ticket--;
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
               }
        }

    }
}

​

2.给当前方法加锁

​
public class Ticket03 implements Runnable{
    private int ticket = 100;

    @Override
    public void run() {
        while (ticket >= 1){
            maiPiao();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
//    给当前方法加锁
    public synchronized void SellingTickets(){

            if(ticket < 1 ){
                System.out.println("卖完了");
                return;
            }else {
                System.out.println("当前在卖第"+ticket+"张票"+"**********"+Thread.currentThread().getName());
                ticket--;

                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

        }
    }
}

​

等待与唤醒机制

wait     notify    notifyAll

public class Chef implements Runnable{

    int num = 0;
    @Override
    public void run() {
    }

    public synchronized void cook() throws InterruptedException {
        if(num == 1){
            this.notifyAll();
            this.wait();
        }else {
            num++;
            System.out.println("做饭");
        }
    }

    public  synchronized void take() throws InterruptedException {
        if(num == 0){
           this.notifyAll();
           this.wait();
        }else {
            num--;
            System.out.println("拿走饭");
        }
    }
}
public class Chef implements Runnable{

    int num = 0;
    @Override
    public void run() {
    }

    public synchronized void cook() throws InterruptedException {
        if(num == 1){
            this.notifyAll();
            this.wait();
        }else {
            num++;
            System.out.println("做饭");
        }
    }

    public  synchronized void take() throws InterruptedException {
        if(num == 0){
           this.notifyAll();
           this.wait();
        }else {
            num--;
            System.out.println("拿走饭");
        }
    }
}

常用类

Math

Calendar  日历类

​
public static void main(String[] args) {
//        日历对象  获取日历对象
        Calendar cal = Calendar.getInstance();
//        System.out.println(cal);
        Date date = new Date();
//        对日历指定时间
        cal.setTime(date);

        int year = cal.get(Calendar.YEAR);
        System.out.println(year + "年");
        int month = cal.get(Calendar.MONTH);
        System.out.println((month + 1) + "月");// 月份从0开始
        int day = cal.get(Calendar.DAY_OF_MONTH);
        System.out.println(day + "日");// 以月份来计算日
        int week = cal.get(Calendar.DAY_OF_WEEK);
        System.out.println(week + "星期");// 从星期日开始索引为1
        String [] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
        System.out.println(weeks[week-1]);
        System.out.println(cal.get(Calendar.HOUR));
        System.out.println(cal.get(Calendar.MINUTE));
        System.out.println(cal.get(Calendar.SECOND));
        System.out.println(cal.get(Calendar.HOUR)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND));
    }

​

Time 

LocalDate

public static void main(String[] args) {
//        获取当前的时间: 年 月 日
        LocalDate date = LocalDate.now();
        System.out.println(date);

        int year = date.getYear();
        System.out.println(year);

        int month = date.getMonthValue();
        System.out.println(month); // 1-12 从1开始

        int day = date.getDayOfMonth();
        System.out.println(day);

//        DayOfWeek week = date.getDayOfWeek();
//        System.out.println(week);
        int week = date.getDayOfWeek().getValue();
        System.out.println("星期"+week);

//        获取自定义时间
        LocalDate date1 = LocalDate.of(2012, 12, 21);
        System.out.println(date1);
    }

LocalTime

 public static void main(String[] args) {
        LocalTime time = LocalTime.now();
        System.out.println(time);
        System.out.println(time.getHour()); // 获取小时 24小时制
        System.out.println(time.getMinute()); // 获取分钟
        System.out.println(time.getSecond());// 获取秒

        LocalTime time1 = LocalTime.of(12, 30, 30);
        System.out.println(time1);
    }

LocalDateTime

public static void main(String[] args) {
        LocalDateTime time = LocalDateTime.now();
        // T 表示时间的分隔符
        System.out.println(time);
        System.out.println(time.getYear());
        System.out.println(time.getMonthValue());
        System.out.println(time.getDayOfMonth());
        System.out.println(time.getHour());
        System.out.println(time.getMinute());
        System.out.println(time.getSecond());
        System.out.println("************************************");
        LocalDateTime time1 = LocalDateTime.of(2012, 12, 21, 12, 21, 12);
        System.out.println(time1);
        LocalDate date = LocalDate.of(2012, 12, 21);
        LocalTime time2 = LocalTime.of(12, 21, 12);
        LocalDateTime time3 = LocalDateTime.of(date, time2);
        System.out.println(time3);

    }

数组

Arrays.sort();        排序从小到大

public static void main(String[] args) {
        int [] arr={5,9,6,7,1,3,2};
        Arrays.sort(arr);
        Arrays.sort(arr,1,7);

        System.out.println(Arrays.toString(arr));
        String [] str={"a9","d3","e1","c6","b7"};
        Arrays.sort(str);
        System.out.println(Arrays.toString(str));
    }

Arrays.binarySearch()        查找数组是排好序的

public static void main(String[] args) {
        int [] arr={5,9,6,7,1,3,2};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        Scanner sca =new Scanner(System.in);
        System.out.println("请输入你要查找的数");
        int num=sca.nextInt();
        int index=Arrays.binarySearch(arr,num);
        if (index<=-1){
            System.out.println("没有找到你输入的"+num+"这个数");
        }else {
            System.out.println("找到你输入的"+num+"这个数");

        }
    }

Arrays.copyOf(数组,长度)        复制数组

Arrays.copyOfRange(数组,from,to)        左闭右开

public static void main(String[] args) {
        int []arr={1,23,6,4,8,7,9};
        int [] arr2= Arrays.copyOf(arr,arr.length);
        int [] arr3= Arrays.copyOf(arr,20);

        System.out.println(Arrays.toString(arr2));
        System.out.println(Arrays.toString(arr3));

        boolean bol =Arrays.equals(arr,arr2);
        System.out.println(bol);
        int [] arr4=Arrays.copyOfRange(arr,2,9);
        System.out.println(Arrays.toString(arr4));
    }

字符串

String

  1. boolean isEmpty():字符串是否为空
  2. int length():返回字符串的长度
  3. String concat(xx):拼接,等价于+
  4. boolean equals(Object obj):比较字符串是否相等,区分大小写
  5. boolean equalsIgnoreCase(Object obj):比较字符串是否相等,不区分大小写
  6. int compareTo(String other):比较字符串大小,区分大小写,按照Unicode编码值比较大小
  7. int compareToIgnoreCase(String other):比较字符串大小,不区分大小写
  8. String toLowerCase():将字符串中大写字母转为小写
  9. String toUpperCase():将字符串中小写字母转为大写
  10. tontatis():判断字符是否存在返回true false
  11. indexof():返回所查字符的下标正向索引
  12. LastIndexof():返回所查字符的下标逆向索引
  13. substring():[form to) 截取字符串输入索引左闭右开 ,一个值从开始到结束
  14. replace():写入两个字符 第一个旧的要被替换的 第二新的要替换的 
  15. charAt():输入索引返回值
public static void main(String[] args) {
        String str="Hello";
        boolean bl =str.isEmpty();//字符串是否为空
        System.out.println(bl);
        System.out.println(str.length());//字符串长度
        System.out.println(str.concat(" World"));//拼接 等于 +
        System.out.println(str.equals("hello"));//比较两个字符串是否相等
        System.out.println(str.equalsIgnoreCase("hello"));//比较两个字符串是否相等 忽略大小写
        //如果第一个字符和参数的第一个字符不等,结束比较,返回第一个字符的ASCII码差值。
        //如果第一个字符和参数的第一个字符相等,则以第二个字符和参数的第二个字符做比较,
        // 以此类推,直至不等为止,返回该字符的ASCII码差值。
        // 如果两个字符串不一样长,可对应字符又完全一样,则返回两个字符串的长度差值
        String str1="Hellos";
        int result =str.compareTo(str1);//比较str 和 str1 大小
        System.out.println(result);
        String str2="Hell";//比较str 和 str2 大小 不区分大小写
        int res =str.compareToIgnoreCase(str2);
        System.out.println(res);
        System.out.println(str.toLowerCase());//将字符串中大写字母转为小写
        System.out.println(str.toUpperCase());//将字符串中小写字母转为大写
        String str3="good good study day day up";
        boolean bool= str3.contains("l");
        System.out.println(bool);
        System.out.println(str3.indexOf("u"));
        System.out.println(str3.lastIndexOf("d"));
        //左闭右开
        System.out.println(str3.substring(3));
        System.out.println(str3.substring(5,16));
        String str4="uisbvwivbwinoican";
        System.out.println(str4.replace("u","H"));
        System.out.println(str4.charAt(6));
        System.out.println(str4);
        System.out.println("i".equals(String.valueOf(str4.charAt(6))));
        System.out.println(Arrays.toString(str4.split("w")));

    }

StringBuffer

public static void main(String[] args) {
        StringBuffer str= new StringBuffer("hello world");
        System.out.println(str.append(" day"));//追加,拼接
        System.out.println(str.insert(6,"day "));//在索引前面添加
        System.out.println(str.delete(6,10));//删除 左闭右开
        str.setCharAt(12,'a');
        System.out.println(str);
        //System.out.println(str.reverse());
        str.setLength(20);
        System.out.println(str);
        str.replace(15,21,"abcdeeghi");
        System.out.println(str);
    }

String、StringBuffer、StringBuilder 

String 字符串常量

StringBuffer 字符串变量(线程安全)

StringBuilder 字符串变量(非线程安全)

StringBuffer 对方法加了同步锁或者对调用的方法加了同步锁,所以是线程安全的。 StringBuilder 并没有对方法进行加同步锁,所以是非线程安全的。

(1)如果要操作少量的数据用 String;

(2)多线程操作字符串缓冲区下操作大量数据用 StringBuffer;

(3)单线程操作字符串缓冲区下操作大量数据用 StringBuilder。

Java 中==和 equals 的区别

== 的作用: 基本类型:比较的就是值是否相同 引用类型:比较的就是地址值是否相同

equals 的作用: 引用类型:默认情况下,比较的是地址值。 注:String、Integer、Date 这些类库中 equals 被重写,比较的是内容而不是地址!

==:比较的是两个字符串内存地址(堆内存)的数值是否相等,属于数值比较;

equals():比较的是两个字符串的内容,属于内容比较。

//        栈 + 栈 = 栈
//        堆 + 堆 = 堆
//        栈 + 堆 = 堆

集合

collection集合根{Set ,List,Queue}所以的继承collection

add(E obj):添加元素对象到当前集合中

 boolean remove(Object obj) :从当前集合中删除第一个找到的与obj对象equals返回true的元素。

boolean removeIf() :删除满足给定条件的此集合的所有元素。

boolean isEmpty():判断当前集合是否为空集合。

boolean contains(Object obj):判断当前集合中是否存在一个与obj对象equals返回true的元素。

int size():获取当前集合中实际存储的元素个数

Object[] toArray():返回包含当前集合中所有元素的数组

有序集合List

ArrayList

查询速度快 增加删除速度慢

 public static void main(String[] args) {

        List<String> list=new ArrayList<>(10);
        list.add("今天");
        list.add("昨天");
        list.add("明天");
        System.out.println(list);
        list.removeIf(e->e.contains("今天"));
        System.out.println(list);
        List<Object> list1 =new ArrayList<>();
        list1.add(3);
        list1.add("aaaa");
        list1.add(true);
        System.out.println(list1);

        System.out.println("====================");
        list1.remove(1);
        System.out.println(list1);
        boolean bl = list.isEmpty();
        System.out.println(bl);
        boolean bl1=list1.contains(true);
        System.out.println(bl1);
        System.out.println(list.size());

    }

LinkedList

查询慢 增加删除速度快

 public static void main(String[] args) {
        List<String> list = new LinkedList<>();
        list.add("大黄");
        list.add("爱");
        list.add("吃");
        list.add("骨头");
        System.out.println(list);

        list.remove(3);
        System.out.println(list);
        System.out.println(list.get(0));
        list.set(0, "小白");
        System.out.println(list);
    }

无序集合set

 set  => 无序的集合  唯一性

HashSet

//        HashSet  哈希表
//        通过 HashMap 来实现的 唯一性  无序的 线程不安全 允许值为null
 Set<String> set1 = new HashSet<>();
        set1.add("肆");
        set1.add("伍");
        set1.add("六");
        set1.add("壹");
        set1.add("贰");
        set1.add("叁");
        System.out.println(set1);
        set1.remove("六");
        System.out.println(set1);
        boolean bo = set1.contains("肆");
        System.out.println(bo);

TreeSet

//        TreeSet  红黑树
//        有序 唯一性
  Set<Integer> set2 = new TreeSet<>();
        set2.add(123);
        set2.add(1);
        set2.add(23);
        set2.add(3);
        set2.add(13);
        set2.add(231);
        System.out.println(set2);

        set2.remove(23);
        System.out.println(set2);
        boolean bol = set2.contains(62);
        System.out.println(bol);

LinkedHashSet

//        LinkedHashSet 哈希表的链接
//        继承自 HashSet 哈希表的快速查询  有序 唯一性
 Set<String> set3 = new LinkedHashSet<>();
        set3.add("王五");
        set3.add("赵六");
        set3.add("张三");
        set3.add("李四");
        System.out.println(set3);

        set3.remove("张三");
        System.out.println(set3);
        boolean bol2 = set3.contains("李四");
        System.out.println(bol2);

迭代器Iterator和foreach

public static void main(String[] args) {
        Set<Integer> set =new HashSet<>();
        set.add(23);
        set.add(123);
        set.add(1);
        set.add(3);
        set.add(2);
        System.out.println(set);

//        for (Integer item:set) {
//            System.out.println(item);
//        }

        Iterator<Integer> ite = set.iterator();

        while (ite.hasNext()){
            Integer s =ite.next();
            System.out.println(s);
        }
    }

泛型

上面在写集合的时候已经用上用的是下面第一种

【修饰符】 class 类名<类型变量列表> 【extends 父类】 【implements 父接口们】{
    
}

【修饰符】 <类型变量列表> 返回值类型 方法名(【形参列表】)【throws 异常列表】{
    //...
}

泛型就是规范你要用的类型,只能是规范之内的

    public static <E> E e1(E e1){
        return e1;
    }
  
    public static <E> String e1(E e1,E e2){
        return "" +e1 + e2;
    }

标签:String,day0726Java,int,基础,System,day0722,println,public,out
From: https://blog.csdn.net/m0_71108047/article/details/140644738

相关文章

  • JAVA基础
    一.编程思维和算法构建  1.抽象基类      ①AbstractCollection      ②AbstractList      ③AbstractQueue      ④AbstractSequentialList      ⑤AbstractMap      ⑥AbstractSet      详情  2.SOLID原则      ......
  • C 语言基础
    C语言1.入门优点:功能强大操作系统、嵌入式、动态库、服务器、应用程序、外挂、其他语言等执行效率高C语言描述问题比汇编语言简练,而代码质量与汇编语言相当可移植性好一个环境上用C语言编写的程序,不改动或稍加改动,就可移植到另一个完全不同的环境中运行缺点:面......
  • Java基础语法(变量)
    +号的使用在Java中,如果在一个运算表达式中,从左往右只要有一方是字符串,那么后续的运算就会被视为字符串的拼接运算。一、基本数据类型整数类型byte:占用1个字节(8位)。取值范围:-128到127。示例:byteb=10;short:占用2个字节(16位)。取值范围:-32768到32......
  • dos基础操作
    打开cmd的方式1.通过菜单Windows+命令提示符2.win+R3.任意文件夹下shift+鼠标右键,打开命令窗口以管理员身份运行cmd通过菜单Windows+命令提示符+右键更多以管理员身份运行常用的dos命令快捷键1.在里面进行各盘符的切换,如C盘切换到D盘用英文状态下使用直接后面加D:或者......
  • 六、IPv6基础知识-地址配置方式
    1.IPv6地址配置方式静态:手工配置静态地址动态:无状态地址自动配置:基于NDP实现,不需要IPv6地址分配服务器保存和管理每个节点的状态信息有状态地址自动配置:基于DHCPv6实现,IPv6地址分配服务器必须保存每个节点的状态信息,并管理这些保存的信息2.无状态地址自动配置无状态自......
  • 【基础教程】Tutorial on Pytorch 结合官方基础文档和个人经验
    参考与前言此教程首次书写于2021年12月份至2022年4月份间不断补充;阅读本文时可以对着代码运行查看官方网址:https://pytorch.org/tutorials/【基本从这里翻译而来更简洁版+碎碎念】https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-beginner-......
  • 关机程序(基础提升)
    目录​​​​1代码2解析想不想让朋友承认自己是猪?运行这段代码不是猪就关机1代码#define_CRT_SECURE_NO_WARNINGS#include<windows.h>#include<string.h>#include<stdio.h>intmain() { charinput[20]={0}; //怎么关机? system("shutdown-s......
  • 猜数字游戏详解(基础知识)
    前言;随着初期编程的学习,是否感觉愈发枯燥无味呢?如果如我所言,那么不妨尝试运行下这个程序,来检验下自己的成果吧。目录1代码2猜数字游戏的实现 1代码#define_CRT_SECURE_NO_WARNINGS//猜数字游戏正式开始#include<stdio.h> #include<stdlib.h> #include<t......
  • MySQL基础知识分享(一)
    写在前面大家好,不知道前面的20题大家写的怎么样,前面分享的20题是SQL中查询的基础题型,这部分被称为DQL部分,是每个学习MySQL必须要学会的部分,下面就让我来介绍MySQL中的其他部分。回顾DQL部分先介绍一下sql语句的语法和执行顺序(序号代表顺序由1~9):select查询列表(7)from......
  • C++初学者指南-6.函数对象--lambdas(基础)
    C++初学者指南-6.函数对象–lambdas(基础)文章目录C++初学者指南-6.函数对象--lambdas(基础)提醒:函数类和对象Lambdas变量捕获保存闭包通用Lambdas(C++14)广义捕获(C++14)相关内容幻灯片提醒:函数类和对象类至少提供一个operator()(…){…}函数能像一个......