dimanche 19 août 2018

How do i get this for loop to work?

I made a helper method to sort an array with numbers in it. Then i call the method in my "main" method and have it return a using string.format. This code works when the string.format portion is outside of the for loop and if statement but when its inside the i doesn't return anything when i tell it too. I know the issue might have to do with my if statement but i'm having trouble finding a solution.

for(int i= 0; i < sal.length; i++) {
        if(sal[i]== 0) {
             str= String.format("Smallest salary:$%,.2f, Name:%s, age:%d" , sal[0], names[0], ages[0]);
             return str;
        }

Aucun commentaire:

Enregistrer un commentaire