What can I do to put question in random mode? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What can I do to put question in random mode?

hi people. am new here and in this world....I am working in a small project, trying to creat a game of questions and answers in cmd. i already have all questions and stages done, but I am not finding out a way to use randin question...

29th Jul 2016, 9:14 AM
Wilson Felisberto
Wilson Felisberto - avatar
3 Answers
+ 2
Store question objects in List. Then use Collections.shuffle(). Then return question to user in sequence starting from first index.
29th Jul 2016, 9:59 AM
WPimpong
WPimpong - avatar
0
use switch case put your question in ech case then make random number to choose which questions should be ask. for create random number get help from my class .... public class randomnum { public static void main(String[] args) { Dice dice = new Dice(); dice.roll(); System.out.println("random num"); System.out.println(dice.getDice1()); } } class Dice { int dice1; void roll() { dice1 = (int)(Math.random()*10) + 1; /* 10 here means random num until 10 you should cheange for your program */ } int getDice1() { return dice1; } }
29th Jul 2016, 9:38 AM
mehdi
- 1
you can use" random" command ..
29th Jul 2016, 2:46 PM
Bhavya Doshi
Bhavya Doshi - avatar