java声明并创建float型数组,double型数组,使用键盘输入的方式给各
java声明并创建float型数组,double型数组,使用键盘输入的方式给各个元素赋值,输出数组元素。再用键盘输入两个数据,分别对数组进行全部填充和全部填充,输出填充后...
java声明并创建float型数组,double型数组,使用键盘输入的方式给各个元素赋值,输出数组元素。再用键盘输入两个数据,分别对数组进行全部填充和全部填充,输出填充后的结果
展开
1个回答
展开全部
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
float[] f=new float[5];
double [] d=new double[5];
System.out.println("给float数组赋值");
Scanner sc=new Scanner(System.in);
f[0]= new Float(sc.nextFloat());
f[1]= new Float(sc.nextFloat());
f[2]= new Float(sc.nextFloat());
f[3]= new Float(sc.nextFloat());
f[4]= new Float(sc.nextFloat());
System.out.println("遍历float数组");
for(float ff:f){
System.out.print(ff+"+++++");
}
System.out.println();
System.out.println("--------------------------------------------------------------------");
System.out.println("给double数组赋值");
Scanner sc1=new Scanner(System.in);
d[0]=new Double(sc1.nextDouble());
d[1]=new Double(sc1.nextDouble());
d[2]=new Double(sc1.nextDouble());
d[3]=new Double(sc1.nextDouble());
d[4]=new Double(sc1.nextDouble());
System.out.println("遍历double数组");
for(double dd:d){
System.out.print(dd+"+++++");
}
System.out.println();
System.out.println("--------------------------------------------------------------------");
System.out.println("填充float数组");
Scanner sc2=new Scanner(System.in);
f[0]= new Float(sc2.nextFloat());
for(int i=1;i<f.length;i++){
f[i]=f[0];
}
System.out.println("遍历float数组");
for(float ff:f){
System.out.print(ff+"+++++");
}
System.out.println();
System.out.println("--------------------------------------------------------------------");
System.out.println("填充double数组");
Scanner sc3=new Scanner(System.in);
d[0]=new Double(sc3.nextDouble());
for(int i=1;i<d.length;i++){
d[i]=d[0];
}
System.out.println("遍历doublet数组");
for(double dd:d){
System.out.print(dd+"+++++");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询