Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How do I get my code to work?(Random generator, min, max, average)
icon5.gif  How do I get my code to work? [message #1155458] Fri, 25 October 2013 23:16 Go to next message
kevin belaen is currently offline kevin belaenFriend
Messages: 1
Registered: October 2013
Junior Member
Hi I need to make a random generator (1-50) that stops when it hits 22. I need to find the max and min of the numbers displayed after it hits 22.

This is what I have so far


public static void main(String[] args) throws FileNotFoundException {
Random generator = new Random();
File infile = new File("myrandomnumbers.txt");
PrintWriter prw = new PrintWriter("myrandomnumbers.txt");
Scanner filescan = new Scanner(infile);
int random;
int max=0;
int min=0;
int avg=0;
int count=0;
int numb;

random = generator.nextInt(51);
max = random;
min = random;


while (count !=22)
{
numb=generator.nextInt(51);
System.out.println(numb);
prw.println(random);

if (random > max)
{
max = random;
}
if (random < min)
{
min = random;
}
}

System.out.println("The min is "+ min);
prw.println("The min is "+ min);
System.out.println("The max is "+ max);
prw.println("The max is "+ max);
//System.out.println("The average is "+ avg);
//prw.println("The average is "+ avg);
}

}

Please help! I'm so lost Sad
Re: How do I get my code to work? [message #1156279 is a reply to message #1155458] Sat, 26 October 2013 12:38 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

This forum is for helping you deal with issues involving downloading,
installing and using Eclipse. It's not to help you with your homework,
to answer general programming or even Java questions.

I would also suggest that you haven't thought very deeply about your
predicament. In the first place, you don't state in very clear terms
what your problem is nor what you think your code is doing that doesn't
conform to purpose given.

For the future, I would suggest that you peruse this link:

http://www.catb.org/esr/faqs/smart-questions.html#intro

Its mere suggestion to use a meaningful subject should, when compared to
the one under which you sent this question, provide you a source of
great enlightenment.

Best of luck.

On 10/25/2013 07:56 PM, kevin belaen wrote:
> Hi I need to make a random generator (1-50) that stops when it hits 22.
> I need to find the max and min of the numbers displayed after it hits 22.
> [snip]
Previous Topic:Not Showing :(
Next Topic:Password for instaling eclipse
Goto Forum:
  


Current Time: Thu Apr 25 09:14:53 GMT 2024

Powered by FUDForum. Page generated in 0.08772 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top