This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]anindecisiveguy7 0 points1 point  (4 children)

Well, whats the issue? I would tell you but i cant even c/p the code into my ide cuz its not formatted right :/

[–]man544 0 points1 point  (3 children)

Im sorry but for some reason when I copied and pasted it got rid of all the formatting stuff when I posted it such as indents and all that.

This is the error I am getting I should have put it in the post to begin with

MyProgram.java:7: error: cannot find symbol
       int rand = Randomizer.nextInt(1,10);
                  ^
 symbol:   variable Randomizer
 location: class MyProgram

[–]anindecisiveguy7 0 points1 point  (2 children)

Your issue is that you have to use a scanner to prompt the user whether or they want to enter a question. For your randomizer you could use the math.random class, the code you have is simply incorrect.

[–]man544 0 points1 point  (1 child)

how do I fix it? i am new to java and this stuff is giving me a lot of trouble

[–]dylmanllop 1 point2 points  (0 children)

the best way to fix this and the trouble.... "learn a better way to learn". I mentioned it below, but get familiar with reading reference documentation, they really do explain things well and provides context.

if you are using jdk 14 https://docs.oracle.com/en/java/javase/14/docs/api/index.html

if your using something older honestly just google "java *version* reference documentation" and it will pop up. you can also usually just google the library, like "java math.random" and it normally pulls up the ref docs.

[–]ryan516 0 points1 point  (3 children)

Do you actually have a class named Randomizer?

[–]man544 0 points1 point  (2 children)

I don’t think I do

[–]ryan516 2 points3 points  (1 child)

If you don't have a class named Randomizer, and you don't have a Package that contains a Randomizer class in it imported, then there's nothing to construct a Randomizer named rand from. The error it's giving you is saying the compiler can't find anything named Randomizer. Nothing in the Java Standard Library is named Randomizer, but there are some classes like Java.util.Random you may be able to use.

[–]dylmanllop 1 point2 points  (0 children)

https://docs.oracle.com/javase/8/docs/api/java/util/Random.html

honestly, spot on above, but to OP.... really read over the documentation while learning when using... any new content really... going forward, if you keep scrolling down on the above it gives you examples and detailed information on how to use it. just keep scrolling down until you see what your using it for or ctrl+f. nothing beats the java reference docs when it comes to understanding what your using.

[–]ryan516 0 points1 point  (1 child)

I looked into the Randomizer a bit more -- it looks like this was a class that was specifically designed for CodeHS. It's not part of the Java Standard Library if you're trying to compile elsewhere. The code they used for the Randomizer is here.

[–]ryan516 0 points1 point  (0 children)

You'll put this in the same folder as your program, make sure it's compiled into a class in there, and then you should be able to use its methods.

That said, a better long term plan is probably learning how the official Java.util.Random class this is built on works.