27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Solutions</strong> to Chapter 7 | Object Oriented Design<br />

61 valid = true;<br />

62 } catch (Exception e) {<br />

63 System.out.println (“Enter a valid coordinate!”);<br />

64 }<br />

65 }<br />

66 valid = false;<br />

67 printBoard();<br />

68 while (!valid) {<br />

69 try {<br />

70 getMove(white);<br />

71 valid = true;<br />

72 } catch (Exception e) {<br />

73 System.out.println (“Enter a valid coordinate!”);<br />

74 }<br />

75 }<br />

76 printBoard ();<br />

77 }<br />

78<br />

79 if (won()!=3) {<br />

80 System.out.println (won () == 1 ? “white” : “black” +<br />

81 “ won!”);<br />

82 } else {<br />

83 System.out.println(“It’s a draw!”);<br />

84 }<br />

85 }<br />

86 }<br />

1 6 5<br />

<strong>Cracking</strong> <strong>the</strong> <strong>Coding</strong> <strong>Interview</strong> | Concepts <strong>and</strong> Algorithms

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!