#千峰逆战班205#数组的操作——每天一个知识点,学会java不再难

数组操作1. 数组地址转移问题【难点】public static void main(String[] args) { int[] arr1 = new int[10]; int[] arr2 = new int[10]; arr1[0] = 10; arr2[0] = 20; System.out.println("arr1[0]:...
摘要由CSDN通过智能技术生成

数组操作

1. 数组地址转移问题【难点】
public static void main(String[] args) {
   
    int[] arr1 = new int[10];
    int[] arr2 = new int[10];
    
    arr1[0] = 10;
    arr2[0] = 20;
    
    System.out.println("arr1[0]:" + arr1[0]);
    System.out.println("arr2[0]:" + arr2[0]);
    
    arr1[5] = 50;
    
    arr2 = arr1;
    
    arr1[0] = 30;
    arr2[0] = 100;
    
    System.out.println("arr1[0]:" + arr1[0]);
    System.out.println("arr2[0]:" + arr2[0]);
    System.out.println("arr2[5]:" + arr2[5]);
    /*
    1. 报错
    2. 30 30 50 
    3. 100 100 50 true
    4. 30 100 50
    5. 50 100 50
    6. 30 100 0
    */
}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0GNw7vdC-1587862980278)(D:\A___课件\NZ2005课件资料\第二周\Day10-数组操作\img\数组地址转移分析图.png)]

问题总结:
	1. 
    int[] arr1 = new int[20];
    int[] arr2 = new int[10];
    
    arr1 = arr2;
    
    arr1[15] ???; 错误的 
    arr1 和 arr2 执行的空间为同一个数组空间

	2. 
	int[] arr1 = new int[10];
	int[] arr2 = new int[10];
	
	arr1[0] = 10;
	arr2[0] = 20;
	arr2[5] = 100;
	
	arr1[0] = arr2[0];
	
	arr1[0] ? 
	arr1[5] ?
	20, 0
	赋值操作完成的是对于元素直接内容的转换,不涉及数组地址转移
	
    3.
    是否可以展示数组中 arr[0] arr[5]元素的空间首地址
    不好意思,不能!!!
2. 数组作为方法的参数
2.1 还是比葫芦画瓢
public static void main(String[] args) {
   

}

/*
(String[] args) 
	String[] args 就是给数组作为方法参数格式,这里main方法需要的参数是一个String 类型的数组

格式:
	public static 返回值类型 方法名(数据类型[] 数组参数名)

数组是可以作为方法的返回值
	【BUT】
	在我没有演示,讲解数组作为返回值使用的情况下,任何人不得使用数组作为返回值
	以防万一你遇到一些你想不到的错误!!!
*/
2.2 数组作为参数分析过程
/*
a. 在一个int类型数组中,存储的内容是1 ~ 10
	int[] arr = {10, 8, 35, 67, 31, 25, 11, 30, 28, 99};
	使用代码找出,元素 == 30 所在下标位置
	
	找出元素30对应的下标位置
		1. 这里需要利用循环遍历数组,查询操作
		2. 查询结果不确定,有可能找到,有可能找不到
		3. 在查询之前我们假设对应的数据时不存在的
			-1 作为保存目标数据的初始值

方法分析:
	固定格式:
    	public static 不要问
    返回值类型:
    	void: 
    		没有返回值,功能变成数据找到直接打印,没有返回到方法外,这是一个黑盒
    		方法。黑盒方法是数据传入之后,没有任何的返回
    	int:
    		返回指定元素的下标位置,没有找到返回-1
   	方法名:
   		indexOf 
   		获取指定元素对应下标
   	形式参数列表:
   		int[] arr:
   			查询数据的源数组,在哪一个数组中进行查询操作,这里需要一个int类型数组
   		int find:
   			指定在数组中查询的元素
   		(int[] arr, int find)
   
方法声明:
	public static int indexOf(int[] arr, int find)
*/
2.3 方法实现和文档注释
/**
* 在指定数组arr中,查询指定元素find所在的下标位置,找到返回值大于等于0,没有找到
* 返回-1
*
* @param arr  查询数据的源数据数组,int类型数组
* @param find 指定在数组中查询的数据,也是对应int类型
* @return 找到指定元素,返回值大于等于0,否则返回-1
*/
public static int indexOf(int[] arr, int find) {
   
    // 假设查询的数据不存在
    int index = -1;
    
    // 遍历整个数组
    for (int i = 0; i < arr
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个用 Shell 脚本自动打卡在微信千峰小程序上的示例: ```shell #!/bin/bash # 请在下面填入你的登录凭据和打卡信息 USERNAME="your_username" PASSWORD="your_password" LOCATION="your_location" # 登录微信 /Applications/WeChat.app/Contents/MacOS/WeChat -login -u $USERNAME -p $PASSWORD # 等待微信启动并扫码登录 sleep 10 # 启动微信小程序 # 请根据你的实际情况修改下面的命令,确保微信小程序在 Dock 中的位置 open -a WeChat && sleep 5 && osascript -e 'tell application "System Events" to tell process "WeChat" to click menu item "千峰小程序" of menu "Window" of menu bar 1' # 等待小程序启动 sleep 10 # 定位到打卡页面 osascript -e 'tell application "System Events" to tell process "WeChat" to tell window 1 to tell web area 1 to set value of text field 1 to "'$LOCATION'"' # 点击打卡按钮 osascript -e 'tell application "System Events" to tell process "WeChat" to tell window 1 to tell web area 1 to click button 1' # 等待打卡完成 sleep 5 # 关闭微信 osascript -e 'tell application "System Events" to tell process "WeChat" to click menu item "退出登录" of menu 1 of menu bar item "WeChat" of menu bar 1' # 退出脚本 exit 0 ``` 请注意,这个脚本是基于 macOS 系统的,使用了微信客户端,因此你需要将微信客户端的路径 `/Applications/WeChat.app/Contents/MacOS/WeChat` 修改为你的实际路径。另外,根据你的实际情况,可能需要对脚本进行一些调整。 请确保你已经安装了 WeChat 命令行工具,并且你已经登录了微信账号。运行脚本后,它将自动打开微信、进入千峰小程序、填写定位信息并点击打卡按钮,最后退出微信。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值