package com.zhao.demo;
public class Demo07 {
/* public static void main(String[] args) {
//getSum(10,20);
//实参
int a=10;
int b=20;
getSum(a,b);
}
//形参
public static void getSum(int a,int b){
int result=a+b;
System.out.println(result);
}*/
public static void main(String[] args) {
/*直接调用
getSum(20,15.6,23);*/
/*赋值调用
double sum=getSum(20,15.5,25.3);
System.out.println(sum);*/
//输出调用
System.out.println(getSum(20.5,13,22.5));
}
package com.zhao.test;
public class Test11 {
//定义一个方法,求长方形的周长,并在方法中打印
public static void main(String[] args) {
getResult(20,5);
}
public static void getResult(double length,double width){
double result=(length+width)*2;
System.out.println(result);
}
}
public static double getSum(double num1,double num2,double num3) {
double result=num1+num2+num3;
return result;
};
}
package com.zhao.test;
public class Test12 {
public static void main(String[] args) {
int[] arr = {11, 22, 33, 44, 55};
//getResult(arr);
//System.out.println("最大值为:"+getMax(arr));
boolean isHave=contains(14,arr);
System.out.println(isHave);
}
//需求:设计一个方法遍历数组并打印在同一行,例如{11,22,33,44,55}
/*public static void getResult(int[] arr){
String result= Arrays.toString(arr);
System.out.println(getResult(arr));
};*/
//设计一个方法求数组的最大值并返回
/* public static int getMax(int[] arr){
int max=arr[0];
for (int i = 1; i < arr.length; i++) {
if (max<arr[i]){
max=arr[i];
}
}
return max;
}*/
//定义一个方法判断数组中的某一个数是否存在,将结果返回
public static boolean contains(int num, int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (num == arr[i]) {
return true;
}
}
return false;
}
}
package com.zhao.test;
import java.util.Arrays;
public class Test13 {
public static void main(String[] args) {
int[] arr={1,2,3,4,5,6,7,8};
int from=2;
int to=5;
copyOfRange(arr,from,to);
}
//定义一个方法copyOfRange(int[] arr,int from,int to)
/*功能:
将数组arr中从索引from(包含)开始到to(不包含)结束的
元素复制到新数组当中
将新数组返回。*/
public static String copyOfRange(int[] arr,int from,int to){
int[] newArr=new int[to-from];
for (int i = from; i < to; i++) {
newArr[i-from]=arr[i];
}
String result=Arrays.toString(newArr);
System.out.println("新的数组为:"+result);
return result;
}
}
标签:arr,Java,int,double,基础,static,result,方法,public
From: https://www.cnblogs.com/javaHane/p/17139553.html