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
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?
+ 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);
+ 1
Use switch or if else
0
Something like that
0
Thanku roel ....