I use a book to learn Java ,and this book contains making a difference question in each end of the chapters. I finished chapter 5, which is all about if and switch statements and operands such as bitwise and logical and loops. Now, it asks me to create a quiz based on global warming. I think i can create one without using any loops and operands. all i need is if statement. However, i want to apply all i have learned from this chapter in this project. So can you give me any idea about using loops ?

Note: I know this question might be considered foolish, but i don't know anywhere else to ask my questions in java. You and my book are the only sources i can reach.

You can use a switch to replace an if in some cases like when you ask multiple choice questions. Then the answer will be 'a', 'b' or 'c', specific characters that you can switch. Use variables like char answer; or int amount; so that you could switch them and operate them if you want.

i want to apply all i have learned from this chapter in this project. So can you give me any idea about using loops ?

Well if you need to loop may be you can use the do while loop and ccontinue on letting the user ask questins until he wishes to terminate

Ex :

Start and let user ask a question and after answering it you may give the user to ask another question or quit, this way you can make use of loop

about everything can be made without for loops, but do you really want to repeat code while you can easily put it in a loop? writing code is not just "getting it to work", it's more about "getting it to work in a manner that costs me the least effort, and is as efficiƫnt as possible".

This article has been dead for over six months. Start a new discussion instead.