SlideShare a Scribd company logo
1 of 6
Download to read offline
Can you write pusdocode for this code please,
import java.util.*;
public class Tic {
private static boolean playersTurn = true;
private static char[][] board ;
private static boolean isDraw;
private static Scanner scannerForInput;
public static void main(String[] args){
scannerForInput = new Scanner(System.in);
board = new char[3][3];
System.out.println("Lets Begin!");
System.out.println("Use comma seperation for Input. Example : 0,0 ");
initBoard();
gameBoard();
runGame( );
gameBoard();
if(isDraw)
System.out.println("No winner");
}
public static void runGame( ){
if(playersTurn == true){
yourTurn( );
}else{
machineTurn( );
}
}
public static void yourTurn(){
System.out.println("Please enter coordinate of your locaiton(x) : ");
String userInput = scannerForInput.nextLine();
int rowPosition = Integer.parseInt(String.valueOf(userInput.charAt(0))) ;
int columnPosition = Integer.parseInt(String.valueOf(userInput.charAt(2))) ;
if(board[rowPosition][columnPosition] == '.'){
board[rowPosition][columnPosition] = 'X';
checkWinner( );
} else if (board[rowPosition][columnPosition] == 'X' || board[rowPosition][columnPosition] ==
'O'){
playersTurn = true;
System.out.println("Please choose an empty space");
runGame( );
}
isDraw=true;
}
public static void machineTurn(){
if(board[0][0] == '.'){
board[0][0] = 'O';
gameBoard();
yourTurn( );
} else if(board[0][2] == '.'){
board[0][2] = 'O';
gameBoard();
yourTurn( );
} else if(board[2][0] == '.'){
board[2][0] = 'O';
gameBoard();
yourTurn( );
} else if(board[2][2] == '.'){
board[2][2] = 'O';
gameBoard();
yourTurn( );
} else if(board[1][1] == '.'){
board[1][1] = 'O';
gameBoard();
yourTurn( );
} else if(board[0][1] == '.'){
board[0][1] = 'O';
gameBoard();
yourTurn( );
} else if(board[1][0] == '.'){
board[1][0] = 'O';
gameBoard();
yourTurn( );
} else if(board[1][2] == '.'){
board[1][2] = 'O';
gameBoard();
yourTurn( );
} else if(board[2][1] == '.'){
board[2][1] = 'O';
gameBoard();
yourTurn( );
}
}
public static void checkWinner(){
String line = null;
line = board[0][0]+"" + board[0][1]+"" + board[0][2]+"";
if (line.equals("XXX")) {
System.out.println("You won!"); gameBoard();
System.exit(1);
}
else if (line.equals("OOO")) {
System.out.println("You lost!"); gameBoard();
System.exit(1);
}
line = board[1][0]+"" + board[1][1]+"" + board[1][2]+"";
if (line.equals("XXX")) {
System.out.println("You won!"); gameBoard();
System.exit(1);
}
else if (line.equals("OOO")) {
System.out.println("You lost!"); gameBoard();
System.exit(1);
}
line = board[2][0]+"" + board[2][1]+"" + board[2][2]+"";
if (line.equals("XXX")) {
System.out.println("You won!"); gameBoard();
System.exit(1);
}
else if (line.equals("OOO")) {
System.out.println("You lost!"); gameBoard();
System.exit(1);
}
line = board[0][0]+"" + board[1][0]+"" + board[2][0]+"";
if (line.equals("XXX")) {
System.out.println("You won!"); gameBoard();
System.exit(1);
}
else if (line.equals("OOO")) {
System.out.println("You lost!"); gameBoard();
System.exit(1);
}
line = board[0][1]+"" + board[1][1]+"" + board[2][1]+"";
if (line.equals("XXX")) {
System.out.println("You won!"); gameBoard();
System.exit(1);
}
else if (line.equals("OOO")) {
System.out.println("You lost!"); gameBoard();
System.exit(1);
}
line = board[0][2]+"" + board[1][2]+"" + board[2][2]+"";
if (line.equals("XXX")) {
System.out.println("You won!"); gameBoard();
System.exit(1);
}
else if (line.equals("OOO")) {
System.out.println("You lost!"); gameBoard();
System.exit(1);
}
line = board[0][0]+"" + board[1][1]+"" + board[2][2]+"";
if (line.equals("XXX")) {
System.out.println("You won!"); gameBoard();
System.exit(1);
}
else if (line.equals("OOO")) {
System.out.println("You lost!"); gameBoard();
System.exit(1);
}
line = board[0][2]+"" + board[1][1]+"" + board[2][0]+"";
if (line.equals("XXX")) {
System.out.println("You won!"); gameBoard();
System.exit(1);
}
else if (line.equals("OOO")) {
System.out.println("You lost!"); gameBoard();
return;
}
System.out.println(line);
machineTurn( );
}
public static void initBoard(){
for(int rowPosition = 0; rowPosition < 3; rowPosition++){
for(int columnPosition = 0; columnPosition < 3; columnPosition++){
board[rowPosition][columnPosition] = '.';
}
}
}
public static void gameBoard(){
String bar = " =============";
System.out.println(" 0 1 2");
System.out.println(bar);
System.out.println("0 " + board[0][0] + " | " + board[0][1] + " | " + board[0][2]);
System.out.println(bar);
System.out.println("1 " + board[1][0] + " | " + board[1][1] + " | " + board[1][2]);
System.out.println(bar);
System.out.println("2 " + board[2][0] + " | " + board[2][1] + " | " + board[2][2]);
System.out.println(bar);
System.out.println("");
}
}

More Related Content

Similar to Can you write pusdocode for this code please,import java.util.;.pdf

import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfADITIEYEWEAR
 
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfimport tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfpreetajain
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfeyewatchsystems
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfkokah57440
 
Utility Classes Are Killing Us
Utility Classes Are Killing UsUtility Classes Are Killing Us
Utility Classes Are Killing UsYegor Bugayenko
 
MineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdfMineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdfaniyathikitchen
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfeyelineoptics
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfstopgolook
 

Similar to Can you write pusdocode for this code please,import java.util.;.pdf (13)

Java file
Java fileJava file
Java file
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdf
 
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfimport tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
 
Utility Classes Are Killing Us
Utility Classes Are Killing UsUtility Classes Are Killing Us
Utility Classes Are Killing Us
 
MineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdfMineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdf
 
3 1-1
3 1-13 1-1
3 1-1
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
201707 CSE110 Lecture 13
201707 CSE110 Lecture 13   201707 CSE110 Lecture 13
201707 CSE110 Lecture 13
 

More from sales88

Caso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdf
Caso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdfCaso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdf
Caso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdfsales88
 
CASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdf
CASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdfCASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdf
CASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdfsales88
 
Caso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdf
Caso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdfCaso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdf
Caso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdfsales88
 
Caso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdf
Caso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdfCaso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdf
Caso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdfsales88
 
CASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdf
CASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdfCASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdf
CASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdfsales88
 
CASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdf
CASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdfCASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdf
CASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdfsales88
 
Caso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdf
Caso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdfCaso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdf
Caso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdfsales88
 
Caso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdf
Caso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdfCaso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdf
Caso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdfsales88
 
Caso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdf
Caso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdfCaso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdf
Caso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdfsales88
 
Caso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdf
Caso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdfCaso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdf
Caso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdfsales88
 
Caso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdf
Caso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdfCaso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdf
Caso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdfsales88
 
Caso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdf
Caso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdfCaso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdf
Caso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdfsales88
 
Caso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdf
Caso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdfCaso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdf
Caso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdfsales88
 
Caso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdf
Caso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdfCaso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdf
Caso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdfsales88
 
Caso 1 Felipe R�os y Tiffany De Los Rios married filling jointl.pdf
Caso 1 Felipe R�os  y Tiffany De Los Rios married filling jointl.pdfCaso 1 Felipe R�os  y Tiffany De Los Rios married filling jointl.pdf
Caso 1 Felipe R�os y Tiffany De Los Rios married filling jointl.pdfsales88
 
Case studyData Protect and PrivacyHuman beings value their priva.pdf
Case studyData Protect and PrivacyHuman beings value their priva.pdfCase studyData Protect and PrivacyHuman beings value their priva.pdf
Case studyData Protect and PrivacyHuman beings value their priva.pdfsales88
 
CASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdf
CASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdfCASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdf
CASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdfsales88
 
case study Private Practice Implements Safeguards for Waiting .pdf
case study Private Practice Implements Safeguards for Waiting .pdfcase study Private Practice Implements Safeguards for Waiting .pdf
case study Private Practice Implements Safeguards for Waiting .pdfsales88
 
Case Study Liberty and the Elderly Patient Ronald is 71 years old..pdf
Case Study Liberty and the Elderly Patient Ronald is 71 years old..pdfCase Study Liberty and the Elderly Patient Ronald is 71 years old..pdf
Case Study Liberty and the Elderly Patient Ronald is 71 years old..pdfsales88
 
Case Study AMr. P tripped and broke her left hip while attempting.pdf
Case Study AMr. P tripped and broke her left hip while attempting.pdfCase Study AMr. P tripped and broke her left hip while attempting.pdf
Case Study AMr. P tripped and broke her left hip while attempting.pdfsales88
 

More from sales88 (20)

Caso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdf
Caso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdfCaso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdf
Caso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdf
 
CASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdf
CASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdfCASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdf
CASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdf
 
Caso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdf
Caso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdfCaso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdf
Caso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdf
 
Caso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdf
Caso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdfCaso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdf
Caso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdf
 
CASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdf
CASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdfCASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdf
CASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdf
 
CASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdf
CASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdfCASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdf
CASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdf
 
Caso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdf
Caso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdfCaso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdf
Caso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdf
 
Caso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdf
Caso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdfCaso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdf
Caso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdf
 
Caso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdf
Caso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdfCaso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdf
Caso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdf
 
Caso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdf
Caso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdfCaso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdf
Caso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdf
 
Caso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdf
Caso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdfCaso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdf
Caso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdf
 
Caso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdf
Caso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdfCaso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdf
Caso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdf
 
Caso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdf
Caso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdfCaso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdf
Caso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdf
 
Caso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdf
Caso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdfCaso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdf
Caso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdf
 
Caso 1 Felipe R�os y Tiffany De Los Rios married filling jointl.pdf
Caso 1 Felipe R�os  y Tiffany De Los Rios married filling jointl.pdfCaso 1 Felipe R�os  y Tiffany De Los Rios married filling jointl.pdf
Caso 1 Felipe R�os y Tiffany De Los Rios married filling jointl.pdf
 
Case studyData Protect and PrivacyHuman beings value their priva.pdf
Case studyData Protect and PrivacyHuman beings value their priva.pdfCase studyData Protect and PrivacyHuman beings value their priva.pdf
Case studyData Protect and PrivacyHuman beings value their priva.pdf
 
CASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdf
CASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdfCASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdf
CASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdf
 
case study Private Practice Implements Safeguards for Waiting .pdf
case study Private Practice Implements Safeguards for Waiting .pdfcase study Private Practice Implements Safeguards for Waiting .pdf
case study Private Practice Implements Safeguards for Waiting .pdf
 
Case Study Liberty and the Elderly Patient Ronald is 71 years old..pdf
Case Study Liberty and the Elderly Patient Ronald is 71 years old..pdfCase Study Liberty and the Elderly Patient Ronald is 71 years old..pdf
Case Study Liberty and the Elderly Patient Ronald is 71 years old..pdf
 
Case Study AMr. P tripped and broke her left hip while attempting.pdf
Case Study AMr. P tripped and broke her left hip while attempting.pdfCase Study AMr. P tripped and broke her left hip while attempting.pdf
Case Study AMr. P tripped and broke her left hip while attempting.pdf
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

Can you write pusdocode for this code please,import java.util.;.pdf

  • 1. Can you write pusdocode for this code please, import java.util.*; public class Tic { private static boolean playersTurn = true; private static char[][] board ; private static boolean isDraw; private static Scanner scannerForInput; public static void main(String[] args){ scannerForInput = new Scanner(System.in); board = new char[3][3]; System.out.println("Lets Begin!"); System.out.println("Use comma seperation for Input. Example : 0,0 "); initBoard(); gameBoard(); runGame( ); gameBoard(); if(isDraw) System.out.println("No winner"); } public static void runGame( ){ if(playersTurn == true){ yourTurn( ); }else{ machineTurn( ); } } public static void yourTurn(){ System.out.println("Please enter coordinate of your locaiton(x) : "); String userInput = scannerForInput.nextLine(); int rowPosition = Integer.parseInt(String.valueOf(userInput.charAt(0))) ; int columnPosition = Integer.parseInt(String.valueOf(userInput.charAt(2))) ; if(board[rowPosition][columnPosition] == '.'){ board[rowPosition][columnPosition] = 'X';
  • 2. checkWinner( ); } else if (board[rowPosition][columnPosition] == 'X' || board[rowPosition][columnPosition] == 'O'){ playersTurn = true; System.out.println("Please choose an empty space"); runGame( ); } isDraw=true; } public static void machineTurn(){ if(board[0][0] == '.'){ board[0][0] = 'O'; gameBoard(); yourTurn( ); } else if(board[0][2] == '.'){ board[0][2] = 'O'; gameBoard(); yourTurn( ); } else if(board[2][0] == '.'){ board[2][0] = 'O'; gameBoard(); yourTurn( ); } else if(board[2][2] == '.'){ board[2][2] = 'O'; gameBoard(); yourTurn( ); } else if(board[1][1] == '.'){ board[1][1] = 'O'; gameBoard(); yourTurn( );
  • 3. } else if(board[0][1] == '.'){ board[0][1] = 'O'; gameBoard(); yourTurn( ); } else if(board[1][0] == '.'){ board[1][0] = 'O'; gameBoard(); yourTurn( ); } else if(board[1][2] == '.'){ board[1][2] = 'O'; gameBoard(); yourTurn( ); } else if(board[2][1] == '.'){ board[2][1] = 'O'; gameBoard(); yourTurn( ); } } public static void checkWinner(){ String line = null; line = board[0][0]+"" + board[0][1]+"" + board[0][2]+""; if (line.equals("XXX")) { System.out.println("You won!"); gameBoard(); System.exit(1); } else if (line.equals("OOO")) { System.out.println("You lost!"); gameBoard(); System.exit(1); } line = board[1][0]+"" + board[1][1]+"" + board[1][2]+""; if (line.equals("XXX")) {
  • 4. System.out.println("You won!"); gameBoard(); System.exit(1); } else if (line.equals("OOO")) { System.out.println("You lost!"); gameBoard(); System.exit(1); } line = board[2][0]+"" + board[2][1]+"" + board[2][2]+""; if (line.equals("XXX")) { System.out.println("You won!"); gameBoard(); System.exit(1); } else if (line.equals("OOO")) { System.out.println("You lost!"); gameBoard(); System.exit(1); } line = board[0][0]+"" + board[1][0]+"" + board[2][0]+""; if (line.equals("XXX")) { System.out.println("You won!"); gameBoard(); System.exit(1); } else if (line.equals("OOO")) { System.out.println("You lost!"); gameBoard(); System.exit(1); } line = board[0][1]+"" + board[1][1]+"" + board[2][1]+""; if (line.equals("XXX")) { System.out.println("You won!"); gameBoard(); System.exit(1); }
  • 5. else if (line.equals("OOO")) { System.out.println("You lost!"); gameBoard(); System.exit(1); } line = board[0][2]+"" + board[1][2]+"" + board[2][2]+""; if (line.equals("XXX")) { System.out.println("You won!"); gameBoard(); System.exit(1); } else if (line.equals("OOO")) { System.out.println("You lost!"); gameBoard(); System.exit(1); } line = board[0][0]+"" + board[1][1]+"" + board[2][2]+""; if (line.equals("XXX")) { System.out.println("You won!"); gameBoard(); System.exit(1); } else if (line.equals("OOO")) { System.out.println("You lost!"); gameBoard(); System.exit(1); } line = board[0][2]+"" + board[1][1]+"" + board[2][0]+""; if (line.equals("XXX")) { System.out.println("You won!"); gameBoard(); System.exit(1); } else if (line.equals("OOO")) { System.out.println("You lost!"); gameBoard(); return; }
  • 6. System.out.println(line); machineTurn( ); } public static void initBoard(){ for(int rowPosition = 0; rowPosition < 3; rowPosition++){ for(int columnPosition = 0; columnPosition < 3; columnPosition++){ board[rowPosition][columnPosition] = '.'; } } } public static void gameBoard(){ String bar = " ============="; System.out.println(" 0 1 2"); System.out.println(bar); System.out.println("0 " + board[0][0] + " | " + board[0][1] + " | " + board[0][2]); System.out.println(bar); System.out.println("1 " + board[1][0] + " | " + board[1][1] + " | " + board[1][2]); System.out.println(bar); System.out.println("2 " + board[2][0] + " | " + board[2][1] + " | " + board[2][2]); System.out.println(bar); System.out.println(""); } }