Results 1 to 3 of 3
  1. #1
    ocomobock is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default 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:

    Quote Originally Posted by jokesRgreat17
    Quote Originally Posted by GimmeSomeJokes
    Quote Originally Posted by jokesRgreat17
    Quote Originally Posted by jokesRgreat17
    Quote Originally Posted by jokesRgreat17
    Quote Originally Posted by GimmeSomeJokes
    Quote Originally Posted by xXMyJokesRock1482Xx
    What do you call outer space? Outer space.
    10/10 would read again
    lolololol rofl hahaha xD
    XD im literaly crying right now
    10/10 would read again
    XD im literaly crying right now
    XD im literaly crying right now
    lolololol rofl hahaha xD



    As you can see, it sometimes makes the same user quote themselves, which I don't want.

    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!");
    		}
    	}
    }
    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.
    Last edited by ocomobock; 09-25-2012 at 12:53 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Getting the last integer in a for loop and checking if the new one is equal to th

    I'm trying to make a program that makes fake and randomized conversations on forums
    I don't think that is something we'd be interested in having on this forum.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    ocomobock is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: Getting the last integer in a for loop and checking if the new one is equal to th

    Quote Originally Posted by Norm View Post
    I don't think that is something we'd be interested in having on this forum.
    Haha yeah, forgot to mention this is for another forum. I'm just doing this cause I'm bored and the other forum is really inactive.

Similar Threads

  1. checking array items are equal
    By trishtren in forum New To Java
    Replies: 5
    Last Post: 10-16-2011, 01:23 PM
  2. Replies: 26
    Last Post: 05-10-2011, 01:31 AM
  3. Entering a while loop with a not equal to string
    By bri1547 in forum New To Java
    Replies: 9
    Last Post: 07-09-2008, 08:10 AM
  4. checking if there are equal numbers
    By nalinda in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 07:21 AM
  5. checking if there are equal numbers
    By nalinda in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •