Results 1 to 3 of 3
- 09-24-2012, 11:09 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 10
- Rep Power
- 0
Getting the last integer in a for loop and checking if the new one is equal to that
Basically, I'm trying to make a program that makes fake and randomized conversations on forums. This is the output:
lolololol rofl hahaha xD
Originally Posted by jokesRgreat17
As you can see, it sometimes makes the same user quote themselves, which I don't want.
I know it has something to do with do while loops, but I get confused by those. I haven't done anything with Java for a while so I can't really remember how do while loops work. Any help would be appreciated.Java Code:package b; import java.util.Random; public class Test2 { static Random r = new Random(); static int rNum1 = r.nextInt(10000); static int rNum2 = r.nextInt(10000); static int rNum3 = r.nextInt(10000); static int max = 16; static int maxd2 = max / 2; static int g1; static int g2; static int g3; static int g4; static String names[] = {"ILikeJokes", "GimmeSomeJokes", "jokesRgreat17"}; static String messages[] = {"lolololol rofl hahaha xD", "XD im literaly crying right now", "10/10 would read again"}; static String sourceMsg[] = {"Hey guys, I just thought of a really funny joke! What do you call a mouse without a keyboard? A perfectly normal mouse.", "What do you call outer space? Outer space."}; static String sourceName[] = {"FunnyDude" + rNum1, "LaughingIsGreat" + rNum2, "xXMyJokesRock" + rNum3 + "Xx"}; public static void main(String args[]) { if (messages.length == names.length) { for(int i = 0; i < max; i++) { g1 = r.nextInt(names.length); g2 = r.nextInt(messages.length); g3 = r.nextInt(sourceMsg.length); g4 = r.nextInt(sourceName.length); if(i < maxd2) { if (i == (maxd2 - 2)) { System.out.print("[quote=\"" + sourceName[g4] + "\"]"); }else { System.out.print("[quote=\"" + names[g1] + "\"]"); } }else { if (i == (maxd2)) { System.out.print("[/quote]" + sourceMsg[g3]); }else { System.out.print("[/quote]" + messages[g2]); } } } }else { System.err.print("The amount of names must be equal to the amount of messages!"); } } }Last edited by ocomobock; 09-24-2012 at 11:53 PM.
- 09-24-2012, 11:29 PM #2
Re: Getting the last integer in a for loop and checking if the new one is equal to th
I don't think that is something we'd be interested in having on this forum.I'm trying to make a program that makes fake and randomized conversations on forumsIf you don't understand my response, don't ignore it, ask a question.
- 09-24-2012, 11:31 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
checking array items are equal
By trishtren in forum New To JavaReplies: 5Last Post: 10-16-2011, 12:23 PM -
need to create loop to force user to input integer
By Tolks in forum New To JavaReplies: 26Last Post: 05-10-2011, 12:31 AM -
Entering a while loop with a not equal to string
By bri1547 in forum New To JavaReplies: 9Last Post: 07-09-2008, 07:10 AM -
checking if there are equal numbers
By nalinda in forum New To JavaReplies: 1Last Post: 11-18-2007, 06:21 AM -
checking if there are equal numbers
By nalinda in forum New To JavaReplies: 0Last Post: 11-18-2007, 02:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks