vendredi 25 octobre 2019

question with java code for else statement. i keep getting error on line 17

Multiple markers at this line - The left-hand side of an assignment must be a variable - Syntax error, insert "AssignmentOperator Expression" to complete Assignment - Syntax error, insert ";" to complete Statement

import java.util.*;

public class MyWhiley1 {

    public static void main(String [] args) {
        int n;
        int numberofInputs;
        int Sum;     

        Scanner input = new Scanner(System.in);

            while ((n = input.nextInt()) !=0) {
                if(n>0) {
                    Sum +=n;
                    numberofInputs++;
                }
                else (n<0) {         //line 17 errors
                    System.out.print("error");
                }

            }
            //avg = sum/n
        System.out.print(Sum/numberofInputs); 
    }

}

Aucun commentaire:

Enregistrer un commentaire