So I'm working on a very basic java assignment, and I believe I understand how the (String [] args) part of the main works. Basically my understanding is that the command line arguments are put into the array of strings called args. However my code won't produce the results I expect. It seems to work fine with no arguments but when I put in either of the other options I'm always greeted with my usage error.
class TicTacToe
{
public char[][] gameboard = { {' ', ' ', ' '},
{' ', ' ', ' '},
{' ', ' ', ' '} };
public static void main(String [] args) {
char play1, play2;
if(args.length == 0) {
play1 = 'h';
play2 = 'h';
}else if(args.length == 1 && args[0] == "-c") {
play1 = 'c';
play2 = 'c';
}else if(args.length == 2 && args[1] == "1") {
play1 = 'c';
play2 = 'h';
}else if(args.length == 2 && args[1] == "2") {
play1 = 'h';
play2 = 'c';
}else{
System.out.println("Usage: java TicTacToe [-c [1|2]]");
return;
}
}
}