dey01---数组,重载 12/6
一维数组
- Arrays.toString(数组)//使数组拼接成一个字符串
- Arrays.sort(数组)快速排序算法
- Arrays.copyOf(数组,长度)把数组赋值一个指定长度的新数组
- 注:此方法可以增加数组长度或减少数组长度
- copyOfRange(数组,开始,结束)截取数组长度,包含开头不包含结尾
- 注:此方法也可以增加数组长度
方法重载
- 在同一个类中,存在方法名相同,但参数列表不同的方法
- 如果在同类中,同名方法的参数个数不同,一定构成重载
- 如果在同类中,同名方法的参数个数相同,
- 需要查看对应位置上参数的类型,而不是参数名,与参数名无关
- (int a,String b)与(int b,String a)--不构成重载
- (int a,String b)与(String a,int b)--构成重载
-----作业1-----
1 public class TestCounter { 2 public static void main(String[] args) { 3 Scanner scanner = new Scanner(System.in); 4 System.out.println("-----计算器-----"); 5 System.out.println("请输入第一个数字:"); 6 float i = scanner.nextFloat(); 7 System.out.println("请输入加减乘除符号"); 8 String c = scanner.next(); 9 System.out.println("请输入第二个数字:"); 10 float x = scanner.nextFloat(); 11 switch (c){ 12 case "+" :float plus = plus(i,x); 13 System.out.println(i+"+"+x+"="+plus); 14 break; 15 case "-" :float reduce = reduce(i,x); 16 System.out.println(i+"-"+x+"="+reduce); 17 break; 18 case "*" :float ride = ride(i,x); 19 System.out.println(i+"*"+x+"="+ride); 20 break; 21 case "/" :float except = except(i,x); 22 System.out.println(i+"/"+x+"="+except); 23 break; 24 } 25 } 26 27 private static float plus(float i,float x) { 28 return i+x; 29 } 30 private static float reduce(float i,float x) { 31 return i-x; 32 } 33 private static float ride(float i,float x) { 34 return i*x; 35 } 36 private static float except(float i,float x) { 37 return i/x; 38 }
浙公网安备 33010602011771号