2020/7/25
介绍:开发java软件不会一直使用notepad++,现在市面上使用最多的开发工具是idea
结构
项目(project)
每个阶段创建一个项目
模块(module)
每天创建一个新模块
包(pack)
公司名com.itheima
类(class)
HelloWorld
快捷键
psvm 生成主方法
sout 生成输出语句
crtl + d 快速复制当前行
crtl + y 删除当前行
crtl + / 单行注释
crtl + shift + / 多行注释
crtl + shift + 上下 快速移动当前行
alt + 右击 选多行代码
arr.fori 加for循环
shift + F6 改名
nextInt().var 生成前面变量接收
int[] arr = new int[3];
int[] arr;
double[] arr;
char[] arr;
int[] arr = {1, 2, 3};
数组是用来保存同类型多个数据
使用场景:比如要存储班级每个学生的年龄,年龄都是整数,如果要去定义变量的话就太麻烦了,所以可以使用一个数组一次性存储多个值。
数组动态初始化就是只给定数组的长度,由系统给出默认初始化值,其初始值:
整数是0,小数是0.0,字符是空字符,布尔是false,引用类型是null
数据类型[] 数组名 = new 数据类型[数组长度];
int[] arr = new int[3];
public class Demo {
public static void main(String[] args) {
int[] arr = new int[5];
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
System.out.println(arr[3]);
System.out.println(arr[4]);
}
}
数据类型[] 数组名 = new 数据类型[]{元素1,元素2,...};
简化写法:
数据类型[] 数组名 = {元素1,元素2,...};
public class Demo {
public static void main(String[] args) {
int arr[] = {1,23,44};
System.out.println(arr);
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
}
}
不i同数组互不影响
基本数据类型:
基本8种
引用数据类型:
类
接口
数组
枚举
基本数据类型存储的是值,引用数据类型存储的是地址
public class ArrayDemo {
public static void main(String[] args) {
int[] arr = new int[3];
System.out.println(arr[3]);
}
}
所有引用类型都能赋值给null
public class ArrayDemo {
public static void main(String[] args) {
int[] arr = new int[3]; //把null赋值给数组
arr = null;
System.out.println(arr[0]);
}
}
public class Demo {
public static void main(String[] args) {
int[] arr = {55, 44, 11, 00, 88};
for (int i = 0; i < arr.length; i++){
System.out.println(arr[i]);
}
}
}
public class Demo {
public static void main(String[] args) {
int[] arr = {12, 33, 55, 76, 88, 99, 754, 22, 46};
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (max < arr[i]) {
max = arr[i];
}
}
System.out.println("该数组的最大值为:" + max);
}
}
public class Demo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int[5];
System.out.println("键盘录入5个数字:");
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (max < arr[i]) {
max = arr[i];
}
}
System.out.println("该数组的最大值为:" + max);
}
}
本文地址:https://blog.csdn.net/weixin_42556780/article/details/107596253
如对本文有疑问, 点击进行留言回复!!
IDEA使用Gradle构建SpringBoot项目工程的详细教程
springboot+mybatis配置clickhouse实现插入查询功能
IDEA遇到Internal error. Please refer to http://jb. gg/ide/critical-startup-errors的问题及解决办法
网友评论