Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class homeworkControl {
- private static Scanner scan = new Scanner(System.in);
- public static void main(String[] args){
- int choice;
- System.out.print("Enter assignment number: ");
- choice = scan.nextInt();
- switch(choice){
- case 9:
- doThis();
- break;
- case 6:
- doQueens();
- break;
- case 4:
- makeThisChange();
- break;
- case 10:
- quickSort();
- break;
- }
- }
- public static void doThis(){
- pascalBoy boy = new pascalBoy();
- }
- public static void doQueens(){
- queenAttack queens = new queenAttack();
- }
- public static void makeThisChange(){
- Maze3D maze = new Maze3D();
- }
- public static void quickSort(){
- double[] stuff = {42.32,28.24,92.104,70.04,2};
- RecursiveSorts.quickSort(stuff);
- for(int i = 0; i < stuff.length; i++){
- System.out.println(stuff[i]);
- }
- }
- }
- public class queenAttack {
- public queenAttack()
- {
- int n = 8;
- solve(0, new int[n]);
- }
- public void outputSolution(final int[] board)
- {
- System.out.println("-----------");
- for (int i = 0; i < board.length; i++) {
- for (int j = 0; j < board[i]; j++) System.out.print(" ");
- System.out.println("8");
- }
- }
- public boolean isSolution(final int[] board)
- {
- for (int i = 0; i < board.length; i++) {
- for (int j = i + 1; j < board.length; j++) {
- if (board[i] == board[j]) return false;
- if (board[i]-board[j] == i-j) return false;
- if (board[i]-board[j] == j-i) return false;
- }
- }
- return true;
- }
- public void solve(int depth, int[] board)
- {
- if (depth == board.length && isSolution(board)) {
- outputSolution(board);
- }
- if (depth < board.length) { // try all positions of the next row
- for (int i = 0; i < board.length; i++) {
- board[depth] = i;
- solve(depth + 1, board);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment