Continuin to fail at Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SKG_Scintill
    Spun a twirly fruitcake,
    FFR Simfile Author
    • Feb 2009
    • 3875

    #16
    Re: Continuin to fail at Java

    That seems a bit redundant, that way I'd need a StringBuffer in my for-loop.
    I checked the StringBuffer and it doesn't have a method that checks all substrings of a given length existing in the String, which is what I made with the for-loop.
    Nevertheless, I'm only a starter at Java with my "less than half a year of class"-experience (first year only had one trimester Java). If I'm overlooking something important, do tell ;)

    Edit: I get the idea that "you can better do it the right way the first time, as in the future you may come across problems if you do it this way", but I approach every problem differently and learn experimentally.
    Last edited by SKG_Scintill; 09-14-2012, 02:04 AM.





    Originally posted by bluguerilla
    So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
    ___
    . RHYTHMS PR LAYERING
    . ZOMG I HAD TO QUIT OUT TERRIBLE
    .

    Comment

    • Patashu
      FFR Simfile Author
      FFR Simfile Author
      • Apr 2006
      • 8609

      #17
      Re: Continuin to fail at Java

      Originally posted by SKG_Scintill
      That seems a bit redundant, that way I'd need a StringBuffer in my for-loop.
      No, my suggestion is you read the original string and build the stringbuilder with every character you decide does not need any further translation. That way you're not modifying the same thing you're reading over.

      EDIT: Wait, maybe I don't understand the problem yet. If the problem is that you want aaaa to be turned into bb before it notices the first aa and turns it into c, well, why not run the second 'if' statement in a for loop, then run the first 'if' statement in a second for loop?
      Last edited by Patashu; 09-14-2012, 02:33 AM.
      Patashu makes Chiptunes in Famitracker:
      http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
      http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
      Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
      http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png

      Comment

      • SKG_Scintill
        Spun a twirly fruitcake,
        FFR Simfile Author
        • Feb 2009
        • 3875

        #18
        Re: Continuin to fail at Java

        Well yeah, making a second for-loop is the easy way out. I'm trying to make code more elegant step by step.





        Originally posted by bluguerilla
        So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
        ___
        . RHYTHMS PR LAYERING
        . ZOMG I HAD TO QUIT OUT TERRIBLE
        .

        Comment

        • UserNameGoesHere
          FFR Veteran
          • May 2008
          • 1114

          #19
          Re: Continuin to fail at Java

          Example:
          Just make sure if aaaa is something special, and aa is also something special, that input of aaaa will work correctly.

          Suppose aaaa -> b
          Suppose aa -> c

          Will input of aaaa go to b or will it go to cc?
          Well, that depends entirely on the order. In this case you probably want the longer match first, i.e. earlier in the list.

          You just have to make sure it works for every case. Think of possible cases which might trip it up, etc...

          Not knowing Japanese, I can't tell you what these cases may be in this particular case/etc... but know that order very well may matter and it may be possible to get stuck in infinite loops if two rules mutually depend on each other, or similar.

          Seriously, hit up that wikipedia link for a background on the subject. Then read the related entries as well. I think that you have not, and I recommend that you do so if you care about the topic. Again, parsing is a tricky topic and there are entire programming languages only for writing parsers.
          Originally posted by Crashfan3
          Man, what would we do without bored rednecks?

          Comment

          • Patashu
            FFR Simfile Author
            FFR Simfile Author
            • Apr 2006
            • 8609

            #20
            Re: Continuin to fail at Java

            Originally posted by SKG_Scintill
            Well yeah, making a second for-loop is the easy way out. I'm trying to make code more elegant step by step.
            If the algorithm is logically expressed by 'do this loop, then do this loop', why not have two loops?
            Patashu makes Chiptunes in Famitracker:
            http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
            http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
            Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
            http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png

            Comment

            • SKG_Scintill
              Spun a twirly fruitcake,
              FFR Simfile Author
              • Feb 2009
              • 3875

              #21
              Re: Continuin to fail at Java

              New problem:

              Is there a way to make a for-loop that repeats its previous steps when the increment increases.

              i.e:
              Code:
              public void recurseLoop(int condition){
              	for(int x = 0; x < condition; x++){
              		//when x=0 it does a command
              		//when x=1 it does the previous command and another command
              		//when x=2 it does the previous 2 commands and another command
              		//when x=3 it does the previous 3 commands and another command
              		//etc
              	}
              }
              I have an ArrayList and every element needs a different command.
              But in some cases the program replaces a value in the ArrayList, hence why it has to keep doing the previous commands.

              Any ideas?
              Last edited by SKG_Scintill; 09-28-2012, 05:52 AM.





              Originally posted by bluguerilla
              So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
              ___
              . RHYTHMS PR LAYERING
              . ZOMG I HAD TO QUIT OUT TERRIBLE
              .

              Comment

              • powerfull
                Woof
                • Jan 2006
                • 174

                #22
                Re: Continuin to fail at Java

                Do you mean something like this?

                Code:
                for (int x = 0; x < condition; x++)
                {
                	for (int y = 0; y < x; y ++)
                	{
                		System.out.println(y);
                	}
                }
                
                // For x = 3, prints out 0, 0, 1, 0, 1, 2
                It goes through the for-loop condition-many times, then it'll go through another for-loop condition-many times with the current x-value as its limit every time. I hope that helps in some way.
                Last edited by powerfull; 09-28-2012, 10:22 AM.


                Some music: http://soundcloud.com/wooffull

                Comment

                • UserNameGoesHere
                  FFR Veteran
                  • May 2008
                  • 1114

                  #23
                  Re: Continuin to fail at Java

                  To do something like this
                  Code:
                  public void recurseLoop(int condition){
                  	for(int x = 0; x < condition; x++){
                  		//when x=0 it does a command
                  		//when x=1 it does the previous command and another command
                  		//when x=2 it does the previous 2 commands and another command
                  		//when x=3 it does the previous 3 commands and another command
                  		//etc
                  	}
                  }
                  You do something like this
                  Code:
                  public void recurseLoop(int condition){
                  	for(int x = 0; x < condition; x++){
                  		switch(x){
                  			case 3:
                  				command3();
                  			case 2:
                  				command2();
                  			case 1:
                  				command1();
                  			case 0:
                  				command0();
                  		}
                  	}
                  }
                  Just a switch statement without breaks -- you rely on fallthrough behavior.
                  Originally posted by Crashfan3
                  Man, what would we do without bored rednecks?

                  Comment

                  Working...