0

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

2
  • 1
    Here System.out.println(sortiert + 1 +":" + array[sortiert]) - variable sortiert is not defined in your main method. Commented Sep 7, 2019 at 10:42
  • could you give me a tip on how to exactly do that? Commented Sep 7, 2019 at 11:04

1 Answer 1

0
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]);
        }
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, turns out i didn't change all the "b"s to "sortiert"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.