The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: Trying to get Java to ask the user for a number

I finally just got it to ask me for a number and add 1. How terrifically frustrating.

Now, I assume to get it to actually do what I want, I'll have to define num2 as num1 * log(num 1)?
And once I do that, I have to repeat the same code for as many variables as I need? Or can I use an if/then to tell it to keep asking for integers until I give it a 0, then calculate the equation I need it to calculate?

Re: Trying to get Java to ask the user for a number

PsychStat.java:7: ';' expected

The compiler got confused and thought there were several errors.
I think the one above is the important one. Statements should end with a ;
The compiler didn't find one and tried to add the contents of the next line to the line without the ; and got confused.
Add an ending ;

The Scanner is a class that has methods that can read input from many sources. The version that you are using will read from the console: new Scanner(System.in);

But if I take away Math, it keeps wanting me to endlessly add parentheses to either side. And for some reason, everywhere I'm searching keeps mentioning double, but I don't want to double my number, I just want it to be multiplied by the log of it.

And once I get that done, I'll actually need it to be the integer multiplied by (log of the integer divided by the log of 2). Will I have to keep making variables to creep up on the equation I want it to do?

Re: Trying to get Java to ask the user for a number

Read the API doc for the Math class's method that you are using. What does it return? The compiler thinks it returns a double value which you are trying to assign to an int variable. That could give: possible loss of precision
For example int x = 1.9999 gives x a value of 1