When trying to make a quiz maker code: I want to ask for the number of questions and then create that many questions, and be able to return each question. I'm confused why the output is not line by line output and input. I have imported java.io.* and java.util.*
public class quiz {
public static void main(String []args){
Scanner kbReader = new Scanner(System.in);
System.out.println("~@{@{@{{{{{{{{{{{{{{{{{{ Quizmaker }}}}}}}}}}}}}}}}}}@}@}@~");
System.out.println("How many questions are in this quiz?");
int numberoQuestions = kbReader.nextInt();
//lets make this input 4
String question [] = new String [numberoQuestions]; //the questions the user has made
int createdQs = 0; //how many questions the user has made
do {
createdQs ++;
System.out.println("What is question " + createdQs);
question [createdQs]= kbReader.nextLine();
}
while(createdQs <= numberoQuestions);
/*
supposed to print
How many questions are in this quiz?
(4)
What is question 1?
(input)
What is question 2?
(input)
What is question 3?
(input)
What is question 4?
(input)
it instead prints
How many questions are in this quiz?
4
What is question 1
What is question 2
age?
What is question 3
height?
What is question 4
school?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at finalProject.quiz.main(quiz.java:18)
*/
System.out.println(question[3] );//prints question 4 but I want it to print question 3
}
}