I am trying to practice algorithms before i start my undergrad in computer science and i am struggling really bad to write algorithms. I understand them once i've been taught them and break them down but when I am trying to do my own, it fails miserable. I am trying a exercise question in a programming textbook, where i have an array and i have to output the largest value or if the array is empty, i have to display -1.

This was the best i can come up with but it still falls way short. Any pointers on what exactly I'm doing wrong.

```
 for(i = 0;i < array.length-1;i++)
     if(array[i] == 0){
         empty = true;
         n = -1;
         System.out.println(n);
     }else{
         largest = array[0];
         if(array[i] > largest){
             largest = array[i];
             System.out.println(array[i]);
         }
     }

```

I see that -1 displayed 10 times but i have found no solution for this and if the array is full, it provides me one then one value.