I'm trying to store 5 different boolean answers (true or false) in 5 different array positions after each loop and then make a method to display the questions which were 'true'.
For example, a test run would go like this:
Question1: Content1 ~ (True or False?) False
Question2: Content2 ~ (True or False?) True
Question3: Content3 ~ (True or False?) False
(loop finished)
Question2: Content2
(exit)
And here is my code so far.
import javax.swing.*;
class booleanTest {
public static void main(String [] params) {
String[] data = {"Test1", "Test2", "Test3", "Test4", "Test5"};
boolean[] user = new boolean[5];
array_input(data, user);
System.out.println(user); // to see if it works atm
System.exit(0);
}
public static String array_input(String[] a, boolean[] b) {
String x = "";
for (int i=0; i<a.length; i++) {
x = JOptionPane.showInputDialog("Data: " + a[i]);
if(x.equals("yes")) {
b[i] = true;
}
else {
b[i] = false;
}
}
return x;
}
//public static String array_print() {
// print the boolean + question here
//}
}
It doesn't work, I understand that the b[i] = true part must be wrong, I should do something else?
true?trueonly, in the methodarray_print()println(Arrays.toString(user))to get the array in readable form.voidmethod.