0

I want to write code for like asking one question and 4 options ...which option is right one we have to display...using array

Quiz game

11th Feb 2019, 4:07 PM
Yash Bafna
Yash Bafna - avatar
5 Answers
+ 1
Since you've been following the Java course I guess that's the language you are going to use for the quizz?
11th Feb 2019, 4:23 PM
Roel
Roel - avatar
+ 1
Then this might work for you: import java.util.Scanner; //this can be an array if you have multiple questions String question = "Which of these statements is correct?"; String[4] answers = new String{ "the main void is not required", "voids can not return anything", "you can't have empty strings", "you don't have to define a variable type"}; //this can be an array if you have multiple questions int[] correct = new int{1}; String out = ""; int user = new Scanner(System.in).nextInt(); System.out.println(question) for(int i = 0; i < 4; i ++){ if(i == correct) out += " "+answers[i].toUpperCase(); else out += " "+answers[i]; } System.out.println(out); if(user == correct) System.out.println("you were correct"); else System.out.println("you weren't correct);
11th Feb 2019, 4:43 PM
Roel
Roel - avatar
+ 1
Use switch or if else
11th Feb 2019, 4:44 PM
Saad Saleem
Saad Saleem - avatar
0
Something like that
11th Feb 2019, 4:43 PM
Roel
Roel - avatar
0
Thanku roel ....
11th Feb 2019, 5:03 PM
Yash Bafna
Yash Bafna - avatar