](/d/file/2024-03-30/15b51ffcffb289f07a8f237466dfb5d8.png#pic_center)
🌈个人主页: Aileen_0v0
🔥热门专栏: 华为鸿蒙系统学习|计算机网络|数据结构与算法|MySQL|
💫个人格言:“没有罗马,那就自己创造罗马~”
文章目录
`实参和形参的关系``方法重载``EXERCISES1-模拟登录`
实参和形参的关系
public class Test { public static void swap(int a , int b){ int tmp = a; a = b; b = tmp;} public static void main(String[] args) { int x = 10; int y = 20; swap(x,y); System.out.println(x); System.out.println(y); }} 

| JAVA 当中无法获取到 局部变量的地址. |
| 实参和形参的关系就像榨汁机一样,丢进去的是橙子,出来的是橙汁. |
public class Test { public static void main(String[] args) { int[] arr = {10,20}; swap(arr); System.out.println("arr[0] = " + arr[0] + "arr[1] = " + arr[1] ); } public static void swap(int[] arr) { int tmp = arr[0]; arr[0] = arr[1]; arr[1] = tmp; }} 
| 虽然数组通过下标可以交换它的位置,但它的内存地址并未发生改变. 所以说,数组不能传某一块的内存地址. |
方法重载
public class Test { public static double add(double d , double c){ return d + c; }// Overload 重载 public static int add(int d , int c){ return d + c; } public static long add(long d , int c){ return d + c; } public static long add(long d , int c , int b){ return d + c; } public static void main(String[] args) { int x = 10; int y = 20; int ret = add(x, y); System.out.println(ret); double d1 = 10.5; double d2 = 12.5; double dd = add(d1, d2); System.out.println(dd); }} 
| 根据上面的代码我们可以知道,方法的重载遵循以下原则: (1)方法名一样. (2)方法的参数列表不一样[个数,数据类型,顺序] (3)返回值是否一样,不影响方法重载. |
EXERCISES1-模拟登录

public class X { public static void main(String[] args) { int count = 3; Scanner scanner = new Scanner(System.in); while (count != 0) { System.out.println("请输入您的密码"); String password = scanner.nextLine(); if (password.equals("123456")) { System.out.println("登陆成功"); return; // 通过 return退出程序 } else { System.out.println("输入错误,请重新登录"); count--; } } System.out.println("程序已退出"); }} 
](/d/file/2024-03-30/f8592fb609f1bd877c36878150f43d46.gif#pic_center)
](/d/file/2024-03-30/95184162685f97fafd349086e4b17f49.gif#pic_center#pic_center)