#What am i doing wrong?

1 messages · Page 1 of 1 (latest)

balmy cargo
#

Im doing a java exercise that is 5 parts. i feel i did everything correctly but for some reason it keeps saying (When the user has given number -1, the program should first print"Give numbers:" and in the end "Thx! Bye!") . this is what i did ```javascript
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Give number:");

    int a = 0;
    int sum = 0;
    int numbers = 0;
    double average = 0;
    int even = 0;
    int odd = 0;
    
    double numbersD = 0;
    double sumD = 0;
    
    while (true){
        
        a = Integer.valueOf(scanner.nextLine());
        int b = ( a%2 );
        
        if (a != -1){
            sum = a + sum;
            sumD = a + sumD;
            numbers = numbers + 1;
            numbersD = numbersD + 1;
            average = sumD / numbersD;
            
            if (b == 1 || b == -1){
                odd = odd + 1;
            } else {
                even = even + 1;
            }
            
        } else if (a == -1){
            System.out.println("Thx! Bye!");
            System.out.println("Sum: " + sum);
            System.out.println("Numbers: " + numbers);
            System.out.println("Average: " + average);
            System.out.println("Even: " + even);
            System.out.println("Odd: " + odd);
            break;
        }   
    }
    
    

}
noble flickerBOT
#

<@&987246399047479336> please have a look, thanks.

rough iron
#

you have System.out.println("Give number:"); at the top of your program. try moving that line into the while loop. Right above where you assign a

balmy cargo
rough iron
#

i've had those moments myself, I get it

balmy cargo
rough iron
#

hm

balmy cargo
#

like this correct?

rough iron
#

yeah, that looks correct

balmy cargo
#

ill try submitting 1 more time to see if it was just a bug

rough iron
#

try moving the "Thx! Bye!" line below printing all the data, so under the "Odd: " line

quartz cape
#

Do you want some like this?

rough iron
#

the instructions say to end with "Thx! Bye!". That might be another problem

balmy cargo
#

it says the outcome should look something like this if the user gives 5, 2, 4, and -1

balmy cargo
quartz cape
rough iron
#

i spot a typo

#

"Give number:" vs "Give numbers:"

balmy cargo
#

I see it😭

#

thank you so much ive been trying to get this working for awhile

#

thank you SO SO much

rough iron
#

glad it's working

quartz cape
#

yeah