Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Reversing My Previous Algorithm of Diagonals

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Reversing My Previous Algorithm of Diagonals

    Title says it all, I come seeking help since I am so close to being done with my mini fun project I am doing.

    Whats Wrong? Below the code represents a 3 stage algorithm which handles a matrix, this version is bug free and if you run it with the Matrix given in the code then you hopefully will see what it is doing. It goes through a diagonal in a Matrix and then eliminates the first letter, reverses and checks then proceeds to the diagonal to its right.

    What do I need? I would like if someone could flip it so instead of starting at wordSearch[0][0] then [1][1], have it start at [9][9] then [8][8] while still following the same rules as I had it setup before. I have been trying for hours for the reverse but to no avail, I will be posting this program once this part is complete for everyone to use even though its pretty useless but plain fun.

    Restating: Have it follow the previous code but just reversing so it goes from the Top Right, full length of 10 to then Top Left of a full length of 1. The code before subtracts that's why there is a counter resetableDec.

    Thanks! Feel free to run it to get the idea of what it does and message me for any more details regarding this.

    The Code

    public static int curRow = 10;
    	public static int curCol = 10;
     
    	public static boolean stop = false;
     
    	public static String[][] wordSearch = {{"H","M","G","R","R","A","U","S","G","U"},
    										   {"U","S","M","J","E","A","F","R","K","W"},
    										   {"X","M","C","L","P","J","D","N","M","S"},
    										   {"I","A","F","O","O","S","M","X","A","F"},
    										   {"R","R","J","O","L","O","O","P","T","N"},
    										   {"T","G","B","C","E","H","X","M","H","W"},
    										   {"A","O","G","H","V","Y","R","B","Y","M"},
    										   {"M","R","A","J","E","L","M","A","X","L"},
    										   {"R","P","W","A","D","T","A","C","Y","B"},
    										   {"H","N","S","A","I","T","E","R","Y","X"}};//Default
     
    	public static String userInput = "";
     
    	public static Scanner kboard = new Scanner(System.in);
     
    	private static void searchDiagonalCenterToRight(String word) {//Center to bottom Right. Diagnol Works, debug to go along column is needed
     
    		int rowOn = 0;
    		int colOn = 0;
     
    		int resetableCol = curCol;
    		resetableCol--;//Just resets everything then starts again.
     
    		int decreaser = curCol;//What to decrease by everytime it runs 10,9,8,7 all the way to 1
    		int resetableDec = decreaser;
    		resetableDec--;
     
    		char c;
     
    		String toFind = word.toUpperCase();
     
    		String developingInverse = "";
     
    		int integer = 0;
     
    		    for(int row = 0; row < curRow; row++)//Matrices Row
    		    {
    		        for(int i = 0; i <= resetableDec; i++)
    		        {
     
    					String developingWord = "";
     
    					integer = i;
     
    		            for(int j = integer; j <= resetableDec; j++,integer++)
    		            {  		
     
    		            	System.out.println("\n\n" + j + " " + integer + " "+ i + " " + row);
    		            	c = wordSearch[j][integer+row].charAt(0);//Sets to whatever letter it is on
    		            	char uC = Character.toUpperCase(c);
    		            	developingWord = developingWord + "" +uC;
     
    						System.out.println("On Row: " + row + " Started From: " + integer + " Now On: " + j);
    						System.out.println("Processing Letter: " + wordSearch[j][integer] + " Adding Letter To: " + developingWord);
     
    						if(toFind.equals(developingWord)) 
    						{
    							rowOn = row; colOn = i;
    							rowOn++; colOn++;
    							System.out.println("\nLocated Word: " + toFind + ". Word Was Diagonal Located Within The Row.");
    							System.out.println("Row " + (rowOn) + " and Starting At Column " + (colOn));
    							stop = true;
    							return;
    						}
     
    						StringBuffer sb = new StringBuffer(developingWord);
    						sb.reverse();
    						developingInverse = sb.toString();
     
    						if(toFind.equals(developingInverse)) {
    							rowOn = row; colOn = i;
    							rowOn++; colOn++;
    							System.out.println("\nLocated Word: " + toFind + ". Word Was Diagonal Located Reversed Within The Row.");
    							System.out.println("Row " + (rowOn) + " and Starting At Column " + (colOn));
    							stop = true;
    							return;
    						}					
    		            }
     
    		        }
    	            resetableDec--;
    		    }
    		    System.out.println("\nNo Matching Word Was Found, Moving To Diagonal Center To Left.");
    	}


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,051
    My Mood
    Mellow
    Thanks
    184
    Thanked 650 Times in 637 Posts

    Default Re: Reversing My Previous Algorithm of Diagonals

    I don't understand why you can't do what you've described. Often, this type of question is asked when someone has found some code on the Internet that they want to change but don't really know how, because they don't understand it. Since you wrote the original, you should understand how it works as it currently functions, and you should know how to modify it to do what you've described. One of your posts also said that you were in a hurry or needed an answer soon. That's an indication that the poster has a deadline and can't take the time to learn the subject. That doesn't sound like your project, because you're doing it as a fun project and personal study.

    What really matters is that you said you've tried some changes that haven't resulted in the desired operation. That's what we need to see to help you. Post the code with the changes you made to change the order in which the array is inspected with any errors and specific questions you have about that approach, then we can help you.

    Good luck!

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reversing My Previous Algorithm of Diagonals

    Like I said, this has been a huge 3 day process of me trying to do it. Its really simple developing code like this since it actually only adds on both areas and makes sure it doesn't go out of bounds, the problem is though, reversing direction. Reversing the direction means subtraction which I kept running into and god only knows why, it starts at [9][9] while I thought I had it programmed to start at [0][9]. I can post the attempted pieces of code I thought they would lead to confusion since the people I have shown already don't understand the 3 nest loop process I developed. Anyways thanks for posting aswell.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,051
    My Mood
    Mellow
    Thanks
    184
    Thanked 650 Times in 637 Posts

    Default Re: Reversing My Previous Algorithm of Diagonals

    Work out the pattern with pencil and paper, and then code it.

Similar Threads

  1. Reversing a String
    By hkfrenchtoast in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 16th, 2014, 03:17 AM
  2. Reversing a String with no Buffer
    By C++kingKnowledge in forum What's Wrong With My Code?
    Replies: 20
    Last Post: March 11th, 2013, 12:54 AM
  3. need help with my program, not clear on diagonals or methods 3, 4 & 6 logic
    By wayfaring_stranger in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 6th, 2012, 05:15 PM
  4. Reversing an Array
    By georger55 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 8th, 2012, 07:22 AM
  5. Reversing an array
    By severus1 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 30th, 2011, 03:54 PM

Tags for this Thread