Solved

Learning Java TwoRandomTester

Posted on 2008-11-03
6
185 Views
Last Modified: 2010-04-21
Any suggestions that would get this run , I would greatlya appreciated it.

To the expression generator.nextInt(n) will evaluate to a random integer between 0 and 1 less than n inclusive.

Determine which of the two randomly generated integers is the arger of the two and display it to the screen in a message:

"The larger of the number ____ and _____ is ____.

Output
Please enter a number of your choice.
100
The first random number picked was 13.
The second random number picked was 67
The larger of the numbers 13 and 67 was 67
**********************************************
package tworandomtester;
import java.util.Random;
import javax.swing.JOptionPane;

public class TwoRandomTester {

    public static void main(String[] args)
    {
       String input;
       
       Random generator = new Random();
       
       int randNum;
     
       input = JOptionPane.showInputDialog("Please enter a number of your choice");
        randNum = generator.nextInt(-1);
       
        JOptionPane.showMessageDialog(null, "The larger of the two numbers si that number");
    }

}
0
Comment
Question by:ca1358
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 22865302
NOW PLEASE DO YOUR HOMEWORK YOURSELF.

It is against the rules of Expert Exchange to probide you with all answers.

I do not need 'easy' points .....................
;JOOP!
0
 

Author Comment

by:ca1358
ID: 22865345
I am glad it is easy for you,  I have been at this for three days and approximately 8 hours per day on each one of these.  
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 22865661
Do not get me wrong.
We are just NOT allowed to do homework, we may help you to go further.
You are supposed to LEARN from this and to IMPROVE yourself.

But I see that you repeatedly ask the same questions.
By now you should know how to write output from a program.

;JOOP!
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 24

Expert Comment

by:sciuriware
ID: 22865668
I think you are not learning from this way to ask questions, because you do
not have enough basic knowledge.
Therefore, please first take a basic course in JAVA fundamentals.

We all took that course some day in the past.

;JOOP!
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22866394
These tutorials are also helpful to get started with:
http://java.sun.com/docs/books/tutorial/

For your assignment above, you are at least trying to solve it yourself which is a start.

I would re-read the question details that you posted above and think about the variable "n" and where it should come from and how it is used.  Sometimes you may find it helpful when you have some mathematical or specific problems like this where they use math variables like take some number "n" and generate a value "a" and a value "b" then you may want to name your variables that in code to start with until you figure out the logic and then change to be more descriptive.  If you can visualize what these values are doing it is even better to start out descriptive variable names like intGivenNumber, intFirstRandomNumber, etc.  

Think as you work through logic, it will help you read code more like plain english (if you don't speak english, name the variables what makes sense in your language). :) Just helps IMHO.
0
 

Author Closing Comment

by:ca1358
ID: 31512612
Thank you for the direction.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
swing controls 2 37
maven not picking latest jar instead picking old jar from .m2 12 74
junit example issue 2 55
What does this method description mean? 1 12
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question