栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java笔记

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java笔记

IDEA中内容辅助键和快捷键
快速生成main方法:psvm 回车;
快速生成输出语句:sout 回车;
代码补全 ctrl+alt+space;
单行注释:ctrl +/;
多行注释:ctrl + shift + / ;
格式化代码:ctrl +alt + L ;

遍历数组

public class helloworld {
    public static void main(String[] args) {
//        定义数组
        int[] arr = {1, 22, 33, 44, 55};
        for (int x = 0; x < arr.length; x++) {
            System.out.println(arr[x]);
        }
    }
}

数组中取最大值

public class helloworld {
    public static void main(String[] args) {
        int[] arr = {1, 22, 33, 44, 55};
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        System.out.println(max);
    }

}

带参数方法定义和调用

public class helloworld {
    public static void main(String[] args) {
//        常量调用
        isEvenNumber(10);
//        变量调用
        int number = 10;
        isEvenNumber(number);
    }
//    定义一个方法,该方法接收一个参数,判断该数据是否为偶数
    public static void isEvenNumber(int number){
        if (number%2==0){
            System.out.println(true);
        }else {
            System.out.println(false);
        }
    }
}

带返回值方法的练习,两个数中取最大的

public class helloworld {
    public static void main(String[] args) {
//    在main()方法中调用定义的方法并使用变量保存
//        int result = getMax(a:10, b:20)
//        System.out.println(result);
        System.out.println(getMax(a:10,b:20));
    }

    //    定义一个方法获取两个数中较大数
    public static int getMax(int a, int b) {
        if (a > b) {
            return a;
        } else {
            return b;
        }
   }
}

遍历数组

public class helloworld {
    public static void main(String[] args) {
//    定义一个数组,用静态初始化完成数组元组初始化
        int[] arr= {11,22,33,44,55};
//        调用方法
        printArray(arr);
    }
//    定义一个方法,用数组遍历通用格式对数组进行遍历。
//    明确返回类型为void,参数int[] arr
    public static void printArray(int[] arr){
        for (int x=0;x 

85

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/310556.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号