
I can get both of the sorts figured out but i cannot figure out how i can declare a two dimensional array without knowing how many elements are going to be in it. The number of elements will depend on how many words he/she types without using an array list.

Thank you. I am having problems with declaring the array. How do i do that without knowing how many elements are going to be input by the user?

Here is a code that performs Bubble Sort using 2 d array.
public class BubbleSortWith2D {
public static void main(String[] args) {
int[][] a = {{3,24}, {4,56}, {1, 98}, {2,36}};
bubbleSort(a);
for(int i = 0;i<a.length;i++) {
String s = "";
for(int j=0;j<a[i].length;j++) s += a[i][j] + " ";
System.out.println(s);
}
}
public static void bubbleSort(int[][] array) {
while(true) {
boolean swapped = false;
for(int i=0;i<array.length-1;i++) {
if (array[i][0] > array[i+1][0]) {
swapped = true;
for(int j=0;j<array[i].length;j++) {
int t = array[i][j];
array[i][j] = array[i+1][j];
array[i+1][j] = t;
}
}
}
if (!swapped) return;
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.