1、利用方法重载,
写三个方法,分别求出int类型绝对值,float类型绝对值和double类型绝对值
public class Tools {
public static void println(int a){ //求int绝对值
int value = a>0?(a):(a*(-1));
System.out.println(value);
}
public static void println(float b){ //求float绝对值
float value = b>0?(b):(b*(-1));
System.out.println(value);
}
public static void println(double c){ //求double绝对值
double value = c>0?(c):(c*(-1));
System.out.println(value);
}
public static void main(String[] args) {
println(-50.3);
}
}
3、将下面给定的数组转置输出
例如 原数组: 1,2,3,4,5,6
转置之后的数组: 6,,5,4,3,2,1
import java.util.*;
public class ShuZu {
public static void main(String[] args) {
int [] score = {1,2,3,4,5,6};
for(int i=0;i
for(int j=0;j
if(score[j]
int temp;
temp=score[j];
score[j]=score[j+1];
score[j+1]=temp;
}
}
}
System.out.println(Arrays.toString(score));//将数组以字符串输出
}
}
4、现在有如下2个数组
数组A: “1,7,5,7,9,2,21,13,45”
数组B: “2,5,8,14,21”
将俩个数组合并为数组C,按顺序排列输出
import java.util.*;
public class ShuZu {
public static void main(String[] args) {
int [] A = {1,7,5,7,9,2,21,13,45};
int [] B = {2,5,8,14,21};
int [] C = new int[A.length+B.length];
System.arraycopy(A, 0, C, 0, A.length);//将A复制到C
System.arraycopy(B, 0, C, A.length,B.length);//将B复制到C
for(int i=0;i
for(int j=0;j
if(C[j]>C[j+1]){
int temp;
temp=C[j];
C[j]=C[j+1];
C[j+1]=temp;
}
}
}
System.out.println(Arrays.toString(C));//将数组以字符串输出
}
}