The Artima Developer Community
Sponsored Link

Java Answers Forum
Int Random Numbers. HELP!

2 replies on 1 page. Most recent reply: Sep 15, 2002 4:53 PM by Abby Parsley

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Brook

Posts: 12
Nickname: brook
Registered: Sep, 2002

Int Random Numbers. HELP! Posted: Sep 15, 2002 9:21 AM
Reply to this message Reply
Advertisement
I am creating random numbers that would print beside each other. Is there an easier way to write the "int" part instead of the following? THANKS.

int num1;
int num2;
int num3;
int num4;
int num5;
int num6;
int num7;
int num8;
int num9;
int num10;


num1 = generator.nextInt(7)+1;
num2 = generator.nextInt(7)+1;
num3 = generator.nextInt(7)+1;
num4 = generator.nextInt(7)+1;
num5 = generator.nextInt(7)+1;
num6 = generator.nextInt(7)+1;
num7 = generator.nextInt(7)+1;
num8 = generator.nextInt(7)+1;
num9 = generator.nextInt(7)+1;
num10 = generator.nextInt(7)+1;


Abby Parsley

Posts: 3
Nickname: aparsley
Registered: Sep, 2002

Re: Int Random Numbers. HELP! Posted: Sep 15, 2002 4:50 PM
Reply to this message Reply
I don't know if I'm understanding you question, but from my interpretation (can you get away from retyping "int" all the time)this is my answer:

YES. Like such => int x, y, z, a, b, c;

This will create int's with all of those names.

Hope this is what you were asking.

Abby Parsley

Posts: 3
Nickname: aparsley
Registered: Sep, 2002

Re: Int Random Numbers. HELP! Posted: Sep 15, 2002 4:53 PM
Reply to this message Reply
Also, you could get the same affect (a list of random numbers) by creating an int array, iterate through the list, and assign the next random int to that index. This can be easily printed too with iteration.

Flat View: This topic has 2 replies on 1 page
Topic: help on project Previous Topic   Next Topic Topic: HttpsURLConnection (?)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use