调试输出Netbeans

时间:2018-08-13 15:44:27

标签: java debugging output

我正在尝试匹配代码中的某些调试输出。当用户正常运行时输入我的代码时,我应该得到以下结果。

run:
Enter the number of elements in the array (less than 100)
6
Enter element number: 0
-5
Enter element number: 1
-6
Enter element number: 2
-4
Enter element number: 3
3
Enter element number: 4
8
Enter element number: 5
1
List as entered is: 
List is: { -5 -6 -4 3 8 1} 
Sorting is done, here are the results from each step
Listing after iteration: 1 { 1 -6 -5 -4 8 3}
Listing after iteration: 2 { 1 3 -6 -5 8 -4}
Listing after iteration: 3 { 1 3 -4 -6 8 -5}
Listing after iteration: 4 { 1 3 -4 -5 8 -6}
Listing after iteration: 5 { 1 3 -4 -5 -6 8}
Listing after iteration: 6 { 1 3 -4 -5 -6 8}
Final Sort is: 
List is: { 1 3 -4 -5 -6 8} 

这应该是我的调试输出。

run:
Arguments are: debug other options could go here
Enter the number of elements in the array (less than 
100)
6
Enter element number: 0
-5
Enter element number: 1
4
Enter element number: 2
-3
Enter element number: 3
2
Enter element number: 4
-1
Enter element number: 5
0
List as entered is: 
List is: { -5 4 -3 2 -1 0} 
Iteration 1 Swapping -5 with 4
Iteration 1 Swapping 4 with -3
Iteration 1 Swapping -3 with 2
Iteration 1 Swapping 2 with -1
Iteration 1 Swapping -1 with 0
Iteration 2 Swapping -5 with 4
Iteration 2 Swapping 4 with -3
Iteration 2 Swapping -3 with 2
Iteration 2 Swapping 2 with -1
Iteration 3 Swapping -5 with 4
Iteration 3 Swapping 4 with -3
Iteration 3 Swapping -3 with 2
Iteration 4 Swapping -5 with 4
Iteration 4 Swapping 4 with -3
Iteration 5 Swapping -5 with 4
Sorting is done, here are the results from each step
Listing after iteration: 1 { 0 -5 4 -3 2 -1}
Listing after iteration: 2 { 0 -1 -5 4 -3 2}
Listing after iteration: 3 { 0 -1 2 -5 4 -3}
Listing after iteration: 4 { 0 -1 2 -3 -5 4}
Listing after iteration: 5 { 0 -1 2 -3 4 -5}
Listing after iteration: 6 { 0 -1 2 -3 4 -5}
Final Sort is: 
List is: { 0 -1 2 -3 4 -5} 

问题是,我只使用Netbeans大约一个月,而且我从未用C ++,Python或我使用过的任何其他语言打印任何类型的调试语句,所以我几乎陷入了困境。我搜索了所有内容,但似乎只能找到如何在Netbeans中运行调试器,这对我在输出中所需的内容毫无用处。以下是我的气泡排序算法的源代码。谢谢。

 public static void main(String args[]) {
    // Allowing you user up to 99 integers, so the int array can can hold everything.
    int arr[] = new int[99];
    Scanner scan = new Scanner(System.in);

    System.out.print("Enter total number of integers you would like to sort: ");
    int n = scan.nextInt();
    // Beginning of while loop to ensure that user input is below 100 
    while (n < 1 || n > 99) {
        System.out.print("You must enter a number between 1 and 99: ");
        n = scan.nextInt();
    }
    // Beginning of for loop to input numbers into the array.
    for (int i = 0; i < n; i++) {
        System.out.print("Input a number: ");
        arr[i] = scan.nextInt();
        //if statement to break the program and send user back to beginning of for loop
        if (arr[i] >= 100) { 
            System.out.println("That number was over 100. Try again.");
            i--; 
        }
    }

    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            // Using Math.abs for my arr[j] to take in all integers the user entered and getting their number regardless of a negative sign being entered.
            if (Math.abs(arr[j]) > Math.abs(arr[j + 1])) {
                int temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
    System.out.println("Sorting is done, here are the results from each step.....");
    // Printing out the sorted array into a list from the "absolute values" of the entered ints of my array
    System.out.println("Final Sorted List :");

    for (int i = 0; i < n; i++) {
        System.out.print(arr[i] + "  ");
    }
//I set up this for loop to print out the arguments I developed for this application.
    for (int i = 0; i < args.length; i++) {
        System.out.print("\n" + "Arg" + i + " is " + args[i]);
    }    
}
}

0 个答案:

没有答案