Still having trouble with the checkWinner

it's making it so that every empty array spot is equal so the checkWinner method is screwing up, any ideas on how to fix this?
import javax.swing.*;
import java.text.*;
import java.applet.*;
import java.io.*;
import java.awt.*;
import java.lang.*;
import java.util.*;
import java.math.*;
import java.sql.*;
import java.security.*;
import java.beans.*;
import javax.crypto.*;
import javax.net.*;
import org.omg.CORBA.*;
import java.awt.color.*;
import java.util.jar.*;
public class TwoDArray
     String [] [] board=new String [3] [3];
     int x;
     public TwoDArray()
          for(int x=0;x<3;x++)
               for(int y=0;y<3;y++)
                    board[x][y]="";
     public void getMove(int row, int col, String letter)
          if(board[row][col].equalsIgnoreCase(""))
               board[row][col]=letter;
          x++;
     public void printBoard()
          for(int x=0;x<3;x++)
               System.out.print("|");
               for(int y=0;y<3;y++)
                    System.out.print(board[x][y]);
               System.out.println("|");
     public boolean checkWinner()
          boolean win=false;
          if(x>=3)
               if(board[0][0].equalsIgnoreCase(board[0][1])&&board[0][0].equalsIgnoreCase(board[0][2]))
                    win=true;
                    return win;
               if(board[0][0].equalsIgnoreCase(board[1][0])&&board[0][0].equalsIgnoreCase(board[2][0]))
                    win=true;
                    return win;
               if(board[0][1].equalsIgnoreCase(board[1][1])&&board[0][1].equalsIgnoreCase(board[2][1]))
                    win=true;
                    return win;
               if(board[0][2].equalsIgnoreCase(board[1][2])&&board[0][2].equalsIgnoreCase(board[2][2]))
                    win=true;
                    return win;
               if(board[1][0].equalsIgnoreCase(board[1][1])&&board[1][0].equalsIgnoreCase(board[1][2]))
                    win=true;
                    return win;
               if(board[2][0].equalsIgnoreCase(board[2][1])&&board[2][0].equalsIgnoreCase(board[2][2]))
                    win=true;
                    return win;
               if(board[0][0].equals(board[1][1])&&board[0][0].equalsIgnoreCase(board[2][2]))
                    win=true;
                    return win;
               if(board[2][0].equals(board[1][1])&&board[2][0].equalsIgnoreCase(board[0][2]))
                    win=true;
                    return win;
          return win;     
     public static void main(String[] args)
          boolean winner=false;     
          String player1="X";
          String player2="O";
          String instructions="Welcome to Tic-Tac-Toe.";
          for (int i = 0;i<instructions.length() ;i++ )
                System.out.print(instructions.charAt(i));
          try
          Thread.sleep(99);
          }catch(InterruptedException e) {e.printStackTrace();}
          System.out.println();
          TwoDArray board=new TwoDArray();
          String input1=JOptionPane.showInputDialog("Enter the row you wish to move in.");
          int rowmove=Integer.parseInt(input1);
          String input2=JOptionPane.showInputDialog("Enter the column you wish to move in.");
          int colmove=Integer.parseInt(input2);
          board.getMove(rowmove,colmove,player1);
          board.printBoard();
          while(winner==false)
               String input3=JOptionPane.showInputDialog("Enter the row you wish to move in.");
               int rowmove2=Integer.parseInt(input3);
               String input4=JOptionPane.showInputDialog("Enter the column you wish to move in.");
               int colmove2=Integer.parseInt(input4);
               board.getMove(rowmove2,colmove2,player2);
               board.printBoard();
               board.checkWinner();
               if(board.checkWinner()==true)
                    System.out.println("O WINS");
                    System.exit(0);
String input5=JOptionPane.showInputDialog("Enter the row you wish to move in.");
          int rowmove3=Integer.parseInt(input5);
String input6=JOptionPane.showInputDialog("Enter the column you wish to move in.");
          int colmove3=Integer.parseInt(input6);
          board.getMove(rowmove3,colmove3,player1);
               board.printBoard();
               board.checkWinner();
               if(board.checkWinner()==true)
               System.out.println("X WINS");
                    System.exit(0);
}

if(board.checkWinner()==true)can be:
if(board.checkWinner())
if(winner==false)can be:
if(!winner)It isn't actually causing trouble right now, but the "x" in the constructor and in printBoard hide the member variable "x". If you aren't careful, you will use the wrong "x" somewhere and confuse yourself. Besides, the member variable "x" is a bad name. It should be "numberOfMoves" or something like that.
Once you fix what scsi-boy said with checkWinner, take out all but the last "return winner;" line, and change it to "if...else if...else if...else if..." It is cleaner to have only one return statement. And, once one "if" is true, you don't need to check the rest.

Similar Messages

  • I am having trouble with the email that is confirming my security questions, it says it has sent it to my gmail but i have checked the email account and nothing has been sent, i have waited 24 hours for it and still nothing

    i am having trouble with the email that is confirming my security questions, it says it has sent it to my gmail but i have checked the email account and nothing has been sent, i have waited 24 hours for it and still nothing.

    Hi Cara154,
    If you are having issues receiving the email verification for your security questions, you may find the following article helpful:
    When you provide a rescue email address during Apple ID creation, you will receive an email from Apple to verify that the email address provided is accurate. If you don't see an email from Apple asking you to verify your rescue email address, you may want to check your SPAM folder. If you still haven't received the email from Apple, you can sign in to My Apple ID (appleid.apple.com) to resend your rescue email address. To resend your verification email, click on Password & Security. Then, click the Resend link located in the Rescue Email Address section.
    Apple Support: Rescue email address and how to reset Apple ID security questions
    http://support.apple.com/kb/ht5312
    Regards,
    - Brenden

  • Are people still having trouble with iPhone/HP Laptops?

    Since I've had my Envy I've had no end of trouble with getting it and the iPhone to play nice. Any my search continues. So far, I have updated every bios, reinstalled Windows 7/iTunes many times, have restored the iPhone far more times than I care to remember and I am STILL having troubles with this thing. Having got through the Syncing issues with the PM55 chipset and iPhone I can now sync with my laptop. However all is not well as it would seem that I cannot sync my photo's. It doesn't matter if I have 0gb, 15gb or 30gb free, iTunes is telling me that there is not enough memory available. This error seems like an old one and there is even some info in the Apple KB but after following all that I still can't get it to sync my photo's.
    Some info on my setup:
    HP Envy 15 (all the latest drivers installed, bios F.24) Core i7-820, 8gb ram etc.
    iPhone 32gb, ver 3.1.3
    iTunes (whatever the latest one is)
    I should add that I can sync my iPhone with an identical install of intunes on my vintage Quad core desktop PC, but as I use my Laptop a lot more (and have all my media, email, and contacts etc on it) I would prefer to sync to it.
    Is there anything that I can do? Its very frustrating to have blown $4k on this equipment and it doesn't work...

    Well I tried deleting the photocache but alas, no luck. I also tried syncing with just the photo's enabled, and it worked! So then I enabled my other media and that copied across too! I thought I was on a bit of a roll here, but now whenever I try and sync it will do one of 3 things:
    iTunes will crash.
    iTunes will indicate that there is not enough memory on the device (+9GB free)
    iTunes will remove the iPhone from the sidebar (and my computer/disk management) even though it will continue to charge.
    Interesting point to note is that it works fine (cable/iphone/itunes/media library) on my desktop and macbook. Still really disappointed that I cannot get these two to cooperate. Also still haven't got any contacts from outlook but that may not be related?

  • Still having trouble with Gallery Slideshow

    Still having trouble with Gallery Slideshow, in Live Preview it bounces to  the top of the page but not centered where I like it.
    Hope someone can help.
    Thanks

    no is not hosted anywhere Im working on a Fantasy Photography site. from the image the top one is design mode and bottom is preivew mode. But my problem is
    as you can see from the images ( red boxes )  it moves when is in preview mode and the sizes of the images change as well as you can see. I dont know why? I tried figuring it out
    but no luck. I hope this helps.
    thanks

  • I have a factory unlocked 4s I'm haveing trouble with the mms withI have a  straight talk I'm useing the sim card swap with tmoblil sim card I'm following the insructions but it works for a while and then its gone. I've set the settings at least ten times

    I have a factory unlocked 4s I'm having trouble with the mms with straight talk I've been useing the sim swap system with tmobile i have put the settings in five times. The setting won't stay it works for a while and then it's gone. I'm not in a good coverage area but when i put the settings in i make sure i'm getting a good signal or near wifi. any suggestions would be great.

        Congrats on your recent upgrade actionkatie! I am sorry to learn of the difficulties you are experiencing with your Samsung Galaxy S4. Let's get to the bottom of this because we want you to love your phone.
    I understand you have done all necessary troubleshooting steps that should have enabled you to send messages to iPhone users without them having to disable iMessage. Have you tried contacting Apple Support regarding the inability to send a text message to iPhone users? Apple can be reached at (800) 275-2273.
    In addition, do you get a certain error message when your WiFi stops working? Have you verifed that Auto Switch network is disabled? To disable this setting simply to go Settings > Wi-Fi > Tap the Menu Key(to the left of the home button) > Select Advanced and it is called `Auto network switch. If you are still experiencing difficulties, please feel free to reach out to us for further assistance.
    Thank You,
    MichelleL_VZW
    VZW Support
    Follow us on Twitter @VZWSUPPORT

  • I HAVE A MAC G5 WITH V10.4 TIGER OS, I AM HAVING TROUBLE WITH THE LETTER "N" ONLY WHEN I USE CAPS AND SHIFT KEYS DOSE IT TYPE THE LETTER "N"SE

    HAVE A MAC G5 WITH V10.4 TIGER OS, I AM HAVING TROUBLE WITH THE LETTER "N" ONLY WHEN I USE CAPS AND SHIFT KEYS DOSE IT TYPE THE LETTER "N". I HAVE CONNECTED A NEW KEYBOARD BUT THE PROBLEM STILL EXIST. WHAT ELSE CAN I DO?

    You might look at "Keyboard Shortcuts" in the Keyboard and Mouse preference pane and see if somehow the lower case n has been inadvertently assigned to something.
    Probably the best solution would be to click the "Restore Defaults" button.

  • Having trouble with the "SIMYO" iPhone 4 internet configuration.. Anybody could help me?

    I am having trouble with the "SIMYO" iPhone 4 internet configuration.. I've been trying to do the configuration 10-15 times now and still, it doesn't work. Anybody could help me please!!

    I don't see SIMYO anywhere on the list of supported carriers: http://support.apple.com/kb/ht1937
    Unless you're talking about a carrier on this list, you're going to have to work it out with them. It's possible their network is just not compatible. They are definitely not a supported carrier.

  • Having trouble with the iOS 8.1.1 download.  Very slow. Just keeps saying preparing update for about 4 hours now. Help

    Having trouble with the iOS 8.1.1 download.  Very slow. Just keeps saying preparing update for about 4 hours now. Help

    Hello there, Cmm405.
    If you're updating your iPad with an over-the-air iOS update, the following Knowledge Base article offers up some practical steps for troubleshooting some of the issues that can arise:
    Resolve issues with an over-the-air iOS update - Apple Support
    In your instance, these sections may prove particularly useful:
    Download takes a long time, or you can't reach update server
    iOS updates require a persistent Internet connection, and the time it takes to download the update will vary according to the size of the update and your Internet speed. You can use your device normally while downloading the iOS update, and iOS will notify you when you can install the update. To improve the speed of the download, avoid downloading other content.
    If you get a message that "an error occurred downloading iOS," try again later. If the issue persists, try updating your device in another network or use iTunes to update your device. Learn more about iOS updates.
    Update does not complete
    If you're installing the update and the progress bar appears to move slowly, be patient. The time an update takes depends on the size of the update and the number of files on the device.
    When you're updating over the air, keep your device connected to a power source so that it doesn't run out of power. If your device does run out of power, connect it to a power source and turn on the device to let the update or restore complete.
    If the update never completes and the progress bar hasn't moved for an extended time, try restarting your device. If you still see the issue after you restart, see what to do if your device appears frozen or won't start.
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • Is PE10 compatible with Windows 8? Having trouble with the organizer.

    Is PE10 compatible with Windows 8? Having trouble with the organizer

    It does sound very Watch Folders-esque, however, it seems strange that there are many folders involved. Are all the folders under a single parent folder perhaps? If so, you could try renaming or moving that folder. Additionally, to clarify, all 60 files are images, correct?
    Additionally, you can try creating a new catalog, just to see if that lets you in. Hold down the Shift key while launching the Organizer. If you get the timing right, the Catalog Manager will appear.

  • I am still having issues with the TOC. I finally got several chapters and sections to show different pictures in the TOC, but have spent hours trying to figure out how to repeat it. This should be so simple. Is there an update? Please help us Apple.

    I am still having issues with the TOC pictures. I got several chapter/section photos to show up, but can't seem to repeat this success. It is some mystery that happened during a time that I had practically given up. This should be such a simple thing. Drag and place a picture into the placeholder and it shows up in the TOC....right? Help, help help! want to get this thing done and it's taken two days of work just get some of the photos to show up. I am going to have to publish this ibook with no photos in several sections.....why can't this be simple? I have even had someone else spend hours trying to figure this out. This software is such a GREAT idea....come on...help with this little part of it.

    I had the same problem myself. I got to the point where I couldn't replace the photo, of a new chapter, in the TOC. What I did was to duplicate an existing chapter that was working and was able to replace it's TOC's photo. I also found that if you try different areas of the photo you can sometimes get it to replace correctly. For example, instead of dragging the new photo to the middle of an existing photo, try dragging it to the right top corner.

  • I need any help i can get, im having trouble with the app find my iphone. I have lost my iphone, checked on the computer, and somehow, took it away so how do i get it back??

    Help
    I need any help i can get, im having trouble with the app find my iphone. I have lost my iphone, checked on the computer, and somehow, took it away so how do i get it back??

    If you are saying that after signing into iCloud it is telling you device is not found, it could be for any number of reasons. If the battery is dead, if the SIM has been removed, or if someone else has the phone and they have restored it, it will not be shown. Also, if you located it once and then sent a remote wipe, it disables the abililty to locate the phone with Find My iPhone.

  • I have a Mac, IPad, I phones, and 2 Windows Vista Pcs and I'm having trouble with the Windows Laptop staying connected.  I have to re-boot after and extended period of time please help

    I have a Mac, IPad, I phones, and 2 Windows Vista Pcs and I'm having trouble with the Windows Laptop staying connected.  I have to re-boot after an extended period of time please help.  Thanks!

    I have a Mac, IPad, I phones, and 2 Windows Vista Pcs and I'm having trouble with the Windows Laptop staying connected.  I have to re-boot after an extended period of time please help.  Thanks!

  • I am having trouble with the Jpeg icons and also now thumbnails not being visable in bith teh Apple finder and now also Adobe Bridge. Can anyone shed any light on this ?

    I am having trouble with the Jpeg icons and also now thumbnails not being visable in bith teh Apple finder and now also Adobe Bridge. Can anyone shed any light on this ?

    Argh - once again, I find my solution right after posting this. Left out one modification to the SWIG script, now it runs in 29 seconds vs C 16 seconds, I can live with that.

  • I am having trouble with the cache in bridge.  When i open I get a message saying bridge has encountered a problem reading the cache try purging in the central cache to correct the situation.  I did that but now when I try to get to the folders where my p

    I am having trouble with the cache in bridge.  When i open I get a message saying bridge has encountered a problem reading the cache try purging in the central cache to correct the situation.  I did that but now when I try to get to the folders where my photos are stored bridge never gets to where I can work.  The message appears "building criteria" and I get an endless loop on the lower left panel.  How do I correct?

    You correct it by leaving Bridge alone until it finishes rebuilding its cache, overnight if necessary.

  • I'm having trouble with the develop module in LR5.4. Any adjustments are taking effect, but only viewable in the filmstrip, not on the main photo. The navigator will go grey, as does the main area too. This applies to all edits done in develop module. I h

    I'm having trouble with the develop module in LR5.4. Any adjustments are taking effect, but only viewable in the filmstrip, not on the main photo. The navigator will go grey, as does the main area too. This applies to all edits done in develop module. I have posted several times on the forum with no responses to address this, and have seen others with the same issue. I have even gone as far as to do a complete re-install of LR5, with no success. I'm at a loss, and I depend on it for so much editing. Please help.

    Reset your preferences file: Resetting (or 'Trashing') the Lightroom Preferences file - Lightroom Forums
    Report back if that doesn't work.

Maybe you are looking for

  • Macbook Pro isn't connecting to the internet unless it's on the guest profile

    I recently purchased a brand new Macbook Pro less than a week ago and I've never been able to connect it to the Internet on my log in. This is my first Mac and honestly I don't believe it was worth the price since I can not use the Internet on it. Th

  • Help, help help help

    When I connect my nano it doesn't add any songs and a warning comes up from my tray that says"iTunes:iTunes.exe Corrupt File run the Chkdsk utility." I typed Chkdsk into run and ran it. Nothing changed. Also when I connect my nano it says "Attempt to

  • Host name in Beehive

    Hi all, I have Beehive 1.3.1 installed and am in the process of configuring it. When I use beekeeper I see that my beehive instances are of the format instance1.localhost.localdomain. Before installation I checked to ensure that I have the fully qual

  • TS1367 Can any one help me? My MacBook air want come on

    Can anyone help me. My MacBook air want come on

  • Can After Effects deystroy a source swf file?

    AFX is acting very odd lately, and since one of my collagues had the same problem, this is clearly not an isolated issue. Here's what happened: I'm working with imported swf files (doing extensive cameramovement between layers, using rasterised forma