Issue
I can't able to print both the arrays at the same time it always come out with
[Jeno, Jaemin, Jaehyun][78, 59, 89][Passed, Failed, Passed]
I wanted it to print out like this
Jeno - 78 - Passed
Jaemin - 59 - Failed
Jaehyun - 89 - Passed
Source code:
import java.util.Arrays;
public class PracticeArray {
public static int [] arr5 = {78,58,89};
public static String names[] = {"Jeno", "Jaemin", "Jaehyun"};
public static String result[] = {"Passed", "Failed", " Passed"};
public static void main (String [] args)
{
System.out.println(Arrays.toString(names) +" - "+ Arrays.toString(arr5) +" - "+ Arrays.toString(result));
}
}
Solution
The easiest way to do this might be to just use an explicit loop:
int [] arr5 = {78,58,89};
String names[] = {"Jeno", "Jaemin", "Jaehyun"};
String result[] = {"Passed", "Failed", "Passed"};
for (int i=0; i < arr5.length; ++i) {
System.out.println(names[i] + " - " + arr5[i] + " - " + result[i]);
}
This prints:
Jeno - 78 - Passed
Jaemin - 58 - Failed
Jaehyun - 89 - Passed
Answered By - Tim Biegeleisen
Answer Checked By - Terry (JavaFixing Volunteer)