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 831319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:11:04+00:00 2026-05-15T04:11:04+00:00

I know I was just asking a question earlier facepalm This is in Java

  • 0

I know I was just asking a question earlier facepalm

This is in Java coding by the way.

Well after everyones VERY VERY helpful advice (thank you guys alot)

I managed to get over half of the program running how I wanted.

Everything is pointing in the arrays where I want them to go. Now I just need to access the arrays so that It prints the correct information randomly.

This is the current code that im using:

http://pastebin.org/301483

The specific code giving me problems is this:

long aa;
int abc;

for (int i = 0; i < x; i++)
{
 aa = Math.round(Math.random()*10);

 String str = Long.toString(aa);
 abc = Integer.parseInt(str);

 String[] userAnswer = new String[x];

 if(abc > x)
 {
  JOptionPane.showMessageDialog(null,"Number is too high. \nNumber Generator will reset.");
  break;
 }

 userAnswer[i] = JOptionPane.showInputDialog(null,"Question "+quesNum+"\n"+questions[abc]+"\n\nA: "+a[abc]+"\nB: "+b[abc]+"\nC: "+c[abc]+"\nD: "+d[abc]);

 answer = userAnswer[i].compareTo(answers[i]);

 if(answer == 0)
 {
  JOptionPane.showMessageDialog(null,"Correct. \nThe Correct Answer is "+answers[abc]+""+i);
 }
 else
 {
  JOptionPane.showMessageDialog(null,"Wrong. \n The Correct Answer is "+answers[abc]+""+i);
 }//else
  • 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-05-15T04:11:05+00:00Added an answer on May 15, 2026 at 4:11 am

    I’m not sure what your question is, but I noticed this line:

    aa = Math.round(Math.random()*10);
    

    If you need a random int between 0 and 10 inclusive, it’s much better to use:

    java.util.Random.nextInt(int n): Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive)

    You’d first create an instance elsewhere (you should only need to do this once in your application):

    Random r = new Random();
    

    Then, whenever you need a random integer between 0 and 10 inclusive, you do:

    aa = r.nextInt(10+1);
    

    You can just write 11, but writing 10+1 perhaps have the added benefit of reminding readers that it’s a half-open range.


    Okay, I just noticed the following:

     aa = Math.round(Math.random()*10);
     String str = Long.toString(aa);
     abc = Integer.parseInt(str);
    

    This makes very little sense. You should be able to just do:

     aa = r.nextInt(10+1);
     abc = (int) aa;
    

    Though frankly I’m not sure if you really need these many variables in the first place. Perhaps you can just write:

     int aa = r.nextInt(10+1);
    

    You also ought to consider using String.format instead of doing all these concatenations.

        System.out.println(
            String.format("%d + %d = %s", 3, 4, 7)
        ); // prints "3 + 4 = 7"
    

    API links

    • java.util.Formatter
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I alwyas use one #ID. just asking this question to know
I don't really know where to begin asking this question, so I'll just try
This could be a very basic Javascript I know but I just can't get
I'm not sure if I'm even asking this question correctly. I just built my
I hope I'm not using stackoverflow.com in the wrong way: asking this question! Recently
I apologize in advance for asking this question, I know similar questions have already
Well this is not the first time im asking these question here but I
I know there have been a few other people asking this question, but my
hey I know I may seem like a complete fool for asking this question
I'm not asking if these are truly random. I just wanted to know if

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.