Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:31:27+00:00 2026-06-15T13:31:27+00:00

Good day! I’m a beginner in programming and I’ve been working on a program.

  • 0

Good day! I’m a beginner in programming and I’ve been working on a program. It uses import java.util.Random because I want my questions to appear randomly in no particular order. But the problem and the only problem is that the question repeats. For an instance, “Are you happy?” is asked three times and “Do you want iPhone 5?” is not even asked. What should I do to just show all the questions in no particular order and so it would not pick the same question many times? So far, this is what I have.

import java.util.Random;
public class RandomQuiz {
    public static void main (String args []){
        int a, b=0;
        String arr [];
        arr = new String [5];
        a = b;
        arr [a] = "Are you happy? \na. yes\t\tb. no\nc. maybe\td. no comment";
        a = b+1;
        arr [a] = "Did you eat breakfast? \na. yes\t\tb. no\nc. maybe\td. no comment";
        a = b+2;
        arr [a] = "Have you watched tv? \na. yes\t\tb. no\nc. maybe\td. no comment";
        a = b+3;
        arr [a] = "Do you want iPhone 5? \na. yes\t\tb. no\nc. maybe\td. no comment";
        a = b+4;
        arr [a] = "Will you have iPad mini? \na. yes\t\tb. no\nc. maybe\td. no comment";

        //prints array values in random
        Random randnum = new Random ();
        for (int count = 1; count <=5; count++){
            a = randnum.nextInt (5);
            System.out.println ("Question # " + count + "\n" + arr [a]);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:31:29+00:00Added an answer on June 15, 2026 at 1:31 pm

    Try this

        Random randnum = new Random (System.currentTimeMillis());
        java.util.HashSet<Integer> myset = new java.util.HashSet<Integer>();
        for (int count = 1; count <=5; count++){
            while(true)  {
                a = randnum.nextInt (5) ;
                if(!myset.contains(a)) { myset.add(new Integer(a)); break;}
            }
            System.out.println ("Question # " + count + "\n" + arr [a]);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Day all, i have been working with http://jsfiddle.net , the sample app i
Good day! I encountered the following error upon running my JSP program. java.lang.IllegalStateException: PWC3991:
Good Day, I have a simple working routine in Perl that swaps two words:
Good day, Stack Overflow. I have a homework assignment that I'm working on this
Good day everybody. I've doing a bit of training at working with Flex and
Good day, Anybody knows of a good java library for retrieving mime type and
Good day! I want to add and remove CSS files according to the size
Good day everyone! So currently I'm working on a project with video processing, so
Good Day to all the people of stackoverflow! Nuff said, anyway I've been familiarizing
Good day everyone! I would just want to ask what is wrong with what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.