import java.util.Scanner;
public class Qa2QeArray2 {
public static void main(String[] args) {
int numOfAircrafts;
Scanner sc = new Scanner(System.in);
System.out.print("Enter num Of Aircrafts : ");
numOfAircrafts = sc.nextInt();
//To Determine the length of the Array
String[] stringArray = new String[numOfAircrafts];
System.out.println("Please enter the names of the Aircrafts : ");
for(int i = 0; i < numOfAircrafts; i++)
{
stringArray[i] = sc.next();
}
//To insert the string values to the Array
double[] doubleArray = new double[numOfAircrafts];
System.out.println("Please enter the shipment rate through each aircraft carrier : ");
for(int i = 0; i < numOfAircrafts; i++)
{
doubleArray[i] = sc.nextDouble();
}
//To insert the double values to the Array
String[] dubArr = new String [stringArray.length * doubleArray.length];
for (int x = 0; x < stringArray.length ; x++)
for (int y = 0; y < doubleArray.length ; y++) {
System.out.println(stringArray[x] + " \t " + doubleArray[y]);
}
}
}
我正在寻找o / p,如下所示
Emirates 20.89 Indigo 10.34
但我得到的是o / p
Emirates 20.89 Emirates 10.34 Indigo 20.89 Indigo 10.34
答案 0 :(得分:0)
您有两个正在运行的嵌套循环。
x
循环和y
循环。
x=0
打印值时x=1
它打印值。
这就是你输出两次的原因。
删除一个循环,你就可以了。