0

so we where tasked to make a tic tac toe w/ out gui or even using array
so here's what ive done so far its still far from complete but i cant seem to get the result i want
but since this is just a test class that would be normal
so here's my problem i cant seem to display the x instead im getting numbers
i know that i still need to make another if in the codition to change the outcome but is there
a way to make this simpler?

package javaapplication3;

import java.util.*;
import static javaapplication3.NewClass.in;




     public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);


  int a = in,b= in,c= in,d= in,e= in,f= in,g= in,h= in,i= in;

         System.out.println("Let's Play Tic Tac Toe!");
         System.out.println("X goes 1st");
         System.out.println("");
         System.out.println("");



     for(int x = 1; x <= 9; x++) {
          System.out.println("Turn:"+x);



            if (x == 1) {
               System.out.print("Input: ");
               in = scan.nextInt();
               a = 1;
               b = 2;
               c = 3;
               d = 4;
               e = 5;      
               f = 6;
               g = 7;
               h = 8;
               i = 9;

         if(in == 1  || in == 2 || in == 3|| in ==4|| in ==5|| in ==6|| in ==7|| in ==8|| in ==9 ){
             in = 'x';
          System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }
            }
            if (x == 2) {
               System.out.print("Input: ");
               in = scan.nextInt();

          System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }if (x == 3) {
               System.out.print("Input: ");
               in = scan.nextInt();

        System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }if (x == 4) {
               System.out.print("Input: ");
               in = scan.nextInt();

          System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }if (x == 5) {
               System.out.print("Input: ");
               in = scan.nextInt();

           System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }if (x == 6) {
               System.out.print("Input: ");
               in = scan.nextInt();

         System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }
          if (x == 7) {
               System.out.print("Input: ");
               in = scan.nextInt();

           System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }if (x == 8) {
               System.out.print("Input: ");
               in = scan.nextInt();

          System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }if (x == 9) {
               System.out.print("Input: ");
               in = scan.nextInt();

          System.out.println("\t["+a+"]"+"["+b+"]"+"["+c+"]  " );
          System.out.println("\t["+d+"]"+"["+e+"]"+"["+f+"]  " );
          System.out.println("\t["+g+"]"+"["+h+"]"+"["+i+"]  " );
                    }



     }

     }

}
2
Contributors
1
Reply
8
Views
3 Years
Discussion Span
Last Post by Paul.Esson
0

Perhaps use a char, and not an int, initalize them all your chars to the numbers you have been using, if it's x's turn and he picks 1, change the 1 to an x.

Then after each turn print the result.

Also I have a feeling you might want to use a switch statement not an if.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.