Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class homeworkControl {
  3. private static Scanner scan = new Scanner(System.in);
  4. public static void main(String[] args){
  5. int choice;
  6. System.out.print("Enter assignment number: ");
  7. choice = scan.nextInt();
  8. switch(choice){
  9. case 9:
  10. doThis();
  11. break;
  12. case 6:
  13. doQueens();
  14. break;
  15. case 4:
  16. makeThisChange();
  17. break;
  18. case 10:
  19. quickSort();
  20. break;
  21. }
  22. }
  23. public static void doThis(){
  24. pascalBoy boy = new pascalBoy();
  25. }
  26. public static void doQueens(){
  27. queenAttack queens = new queenAttack();
  28. }
  29. public static void makeThisChange(){
  30. Maze3D maze = new Maze3D();
  31. }
  32. public static void quickSort(){
  33. double[] stuff = {42.32,28.24,92.104,70.04,2};
  34. RecursiveSorts.quickSort(stuff);
  35. for(int i = 0; i < stuff.length; i++){
  36. System.out.println(stuff[i]);
  37. }
  38. }
  39. }
  40.  
  41. public class queenAttack {
  42. public queenAttack()
  43. {
  44. int n = 8;
  45. solve(0, new int[n]);
  46. }
  47. public void outputSolution(final int[] board)
  48. {
  49. System.out.println("-----------");
  50. for (int i = 0; i < board.length; i++) {
  51. for (int j = 0; j < board[i]; j++) System.out.print(" ");
  52. System.out.println("8");
  53. }
  54. }
  55.  
  56.  
  57. public boolean isSolution(final int[] board)
  58. {
  59. for (int i = 0; i < board.length; i++) {
  60. for (int j = i + 1; j < board.length; j++) {
  61. if (board[i] == board[j]) return false;
  62. if (board[i]-board[j] == i-j) return false;
  63. if (board[i]-board[j] == j-i) return false;
  64. }
  65. }
  66. return true;
  67. }
  68.  
  69. public void solve(int depth, int[] board)
  70. {
  71. if (depth == board.length && isSolution(board)) {
  72. outputSolution(board);
  73. }
  74. if (depth < board.length) { // try all positions of the next row
  75. for (int i = 0; i < board.length; i++) {
  76. board[depth] = i;
  77. solve(depth + 1, board);
  78. }
  79. }
  80. }
  81.  
  82. }
Add Comment
Please, Sign In to add comment