• 【每日一题】第二天


    ❤️ Author: 老九
    ☕️ 个人博客:老九的CSDN博客
    🙏 个人名言:不可控之事 乐观面对
    😍 系列专栏:每日一题

    选择

    在这里插入图片描述






    toLowerCase不是在本身修改,而是产生了一个新的对象,底层源码是new了一个新的string,而如果本身是小写的,就返回this,不会new一个新的对象

    在这里插入图片描述

    先创建了一个新的对象,里面的是静态方法,静态方法不依赖于对象,所以可以编译通过正确运行

    在这里插入图片描述

    子类的构造方法必须调用父类的构造方法,如果使用super()就显示调用父类的构造方法了,this和super不能出现在同一个构造函数中,也不能在static环境中使用,因为要依赖对象

    在这里插入图片描述

    创建子类的对象默认调用父类的构造方法

    在这里插入图片描述

    static不能定义局部变量,只能定义静态成员变量,也不能放在静态方法中

    在这里插入图片描述

    abstract不能修饰字段
    抽象方法不能加大括号

    在这里插入图片描述

    类中的constructor(构造方法)可以省略,构造方法必须和类重名,但方法也可以和类重名,构造方法可以重载

    在这里插入图片描述

    对成员变量的赋值必须在方法中实现

    在这里插入图片描述

    编程题1

    在这里插入图片描述

    整体数据进行逆置
    然后每个单词进行逆置

    public class test1 {
        public static void reverse(char[] array,int start,int end){
            while(start < end){
                char tmp = array[start];
                array[start] = array[end];
                array[end] = tmp;
                start ++;
                end --;
            }
        }
    
        public static void main(String[] args) {
           Scanner scan = new Scanner(System.in);
           String s = scan.nextLine();
            char[] ch = s.toCharArray();
            int len = ch.length;
            //整体进行了逆置
            reverse(ch,0,len-1);
            int i = 0;//遍历数组
            while(i<len){
                int j = i;
                while(j<len && ch[j] != ' '){
                    j++;
                }
                if(j<len){
                    reverse(ch,i,j-1);
                    i=j+1;
                }else{
                    reverse(ch,i,j-1);
                    i= j;
                }
            }
            String str = new String(ch);
            System.out.println(str);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    编程题2

    在这里插入图片描述
    在这里插入图片描述

    public class test1 {
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            int [] array = new int[n+1];
            for(int i = 0;i<n;i++){
                array[i]=scan.nextInt();
            }
            int i = 0;
            int count = 0;
            while(i<n){
                if(array[i]<array[i+1]){
                    while(i<n && array[i]<array[i+1]){
                        i++;
                    }
                    count++;
                    i++;
                }else if(array[i] == array[i+1]){
                    i++;
                }else{
                    while(i<n && array[i]>array[i+1]){
                        i++;
                    }
                    count++;
                    i++;
                }
            }
            System.out.println(count);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    ————————————————————————
    ♥♥♥码字不易,大家的支持就是我坚持下去的动力♥♥♥
    版权声明:本文为CSDN博主「亚太地区百大最帅面孔第101名」的原创文章

  • 相关阅读:
    JavaScript入门⑦-DOM操作大全
    源码安装python
    一起Talk Android吧(第三百六十四回:多线程之同步块)
    Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
    maven-之Lifecycle详解
    计算机毕业设计Java罪犯信息管理系统(源码+系统+mysql数据库+lw文档)
    你绝对不知道的JMeter中如何实现接口之间的关联?
    OpenCV入门8:区域分割和区域生长
    简单易用,效果卓越的电子期刊制作网站
    Linux环境(Ubuntu)上的防火墙工具使用方法
  • 原文地址:https://blog.csdn.net/partworld/article/details/125557989