easy for loop not working

So I was trying to make (EX) Enter some values: 1 -2 -3 2 5 num of positive num is 5 num of neg num is -3 total is 3 avg is .6 I wanted to make it like this but when i run it, it doesn't work what part is error???

import java.util.*;


public class Welcome {

public static void main(String [] args){

    Scanner input = new Scanner(System.in);
System.out.print("Enter an int value, the program exits if the input is 0: ");
    int num = input.nextInt();
    int countpos = 0;
    int countneg = 0;
    int totalnum = 0;
    int total = 0;
    double avg = 0.0;

    while(num != 0){

        if(num < 0)
            countpos++;
        else
            countneg++;

        total = total + num;
        totalnum++;
    }

    System.out.print("num of pos is: " + countpos);
    System.out.print("num of neg is: " + countneg);
    System.out.print("total is: " + total);
    System.out.print("the avg is: " + total / totalnum );

}

}

Answers


you have to do num = input.nextInt(); in the loop too

 while(num != 0){

        if(num < 0)
            countpos++;
        else
            countneg++;

        total = total + num;
        totalnum++;

        num = input.nextInt();
    }

Need Your Help

CSS positioning panels problems

html5 user-interface css3 panels css

I've been trying to make this layout for weeks now but i just cant seem to get it like this at all!

Does it make sense for an ASP.NET Web API method to return IQueryable<T>?

iqueryable asp.net-web-api deferred-execution

I'm working on a project that uses the new Web API and I noticed somebody is returning an IQueryable&lt;T&gt; from a Get method.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.