如何组合和输出两个字符串数组?

时间:2022-05-07 12:19:03
String[] row = {"Below 0 degrees", "From 0 to 32", "From 33 to 50", "From 51 to 60", "From 61 to 70", "From 71 to 90", "Above 90" };
String[] suit = {"Very cold", "Cold", " Mild", "Very mild", "Warm", "Very warm", "Hot" };

I have tried setup in an array, how I do I continue now?

我已尝试在阵列中设置,我现在如何继续?

My desired output:

我想要的输出:

Below 0 degrees = Very cold

低于0度=非常冷

From 0 to 32 = Cold

从0到32 =冷

From 33 to 50 = Mild

从33到50 =温和

From 51 to 60 = Very mild

从51到60 =非常温和

From 61 to 70 = Warm

从61到70 =温暖

From 71 to 90 = Very warm

从71到90 =非常温暖

Above 90 = Hot

高于90 =热

1 个解决方案

#1


2  

If I understand you correctly, I think this is what you're trying to do:

如果我理解正确,我认为这就是你要做的事情:

String[] row = {"Below 0 degrees", "From 0 to 32", "From 33 to 50", "From 51 to 60", "From 61 to 70", "From 71 to 90", "Above 90" }; 
String[] suit = {"Very cold", "Cold", " Mild", "Very mild", "Warm", "Very warm", "Hot" };

for(int i=0; i<row.length;i++) {
    System.out.println(row[i] + "=" + suit[i]);
    System.out.println();
}

Or perhaps a map would work even better if row and suit are so linked:

或者如果行和套装如此相关,地图可能会更好:

Map<String, String> rowSuit = new LinkedHashMap<>();

rowSuit.put("Below 0 Degrees", "Very Cold");
rowSuit.put("From 0 to 32", "Cold");
...

for(Entry<String, String> e : rowSuit.entrySet()) {
    System.out.println(e.getKey() + "=" + e.getValue());
    System.out.println();
}

#1


2  

If I understand you correctly, I think this is what you're trying to do:

如果我理解正确,我认为这就是你要做的事情:

String[] row = {"Below 0 degrees", "From 0 to 32", "From 33 to 50", "From 51 to 60", "From 61 to 70", "From 71 to 90", "Above 90" }; 
String[] suit = {"Very cold", "Cold", " Mild", "Very mild", "Warm", "Very warm", "Hot" };

for(int i=0; i<row.length;i++) {
    System.out.println(row[i] + "=" + suit[i]);
    System.out.println();
}

Or perhaps a map would work even better if row and suit are so linked:

或者如果行和套装如此相关,地图可能会更好:

Map<String, String> rowSuit = new LinkedHashMap<>();

rowSuit.put("Below 0 Degrees", "Very Cold");
rowSuit.put("From 0 to 32", "Cold");
...

for(Entry<String, String> e : rowSuit.entrySet()) {
    System.out.println(e.getKey() + "=" + e.getValue());
    System.out.println();
}