Search code examples
javabubble-sort

Java error - java: cannot find symbol - Bubblesort


I am learning how to code in Java and currently trying to create a simple Bubblesort algorithm. But when i run the program it says java: cannot find symbol.

Since im pretty new to this i don't really know what to do about it.

    public int[] liste ={5,2,4,9,8,11};
    public int[] sortieren(){

        int unsortiert;
        for(int sortiert = 0; sortiert < liste.length -1; sortiert++){

            if(liste[sortiert] < liste[sortiert+1]){
                continue;
            }

            unsortiert = liste[sortiert];
            liste[sortiert] = liste[sortiert+1];
            liste[sortiert+1] = unsortiert;
            sortieren();
        }
        return  liste;
    }

    public static void  main (String[] args){
        KartenSort bs = new KartenSort();
        int[] array = bs.sortieren();
        for (int b=0;b < array.length; b++){
            System.out.println(sortiert + 1 +":" + array[sortiert]);
        }
    }

Error:(25, 32) java: cannot find symbol symbol: variable sortiert location: class KartenSort

and:

Error:(25, 58) java: cannot find symbol symbol: variable sortiert location: class KartenSort


Solution

  • for (int b=0;b < array.length; b++){
                System.out.println(sortiert + 1 +":" + array[sortiert]);
            }
    

    replace your above code by

    for (int b=0;b < array.length; b++){
                System.out.println(b + 1 +":" + array[b]);
            }