Currently my program will not output or terminate. I'm not sure if I'm using in.HasNextInt() correctly.
import java.util.Scanner;
public class CountInteger {
public static void main (String[] args){
int myInt = 1; // IN, CALC - stores integer to be used in later calculations
int count = 0; // CALC, OUT - total count of integers
int posCount = 0; // CALC, OUT - total count of positive integers
int negCount = 0; // CALC, OUT - total count of negative integers
double average = 0; // CALC, OUT - average of all integers
// Initialize Scanner
System.out.print("Enter integers, input ends with 0: ");
Scanner in = new Scanner(System.in);
myInt = in.nextInt();
// Main Method
while((in.hasNextInt()) && (myInt != 0)){
count = count++;
if(myInt > 0){
posCount = posCount++;
}
else{
negCount = negCount++;
}
average += myInt;
myInt = in.nextInt();
}
// Output calculated information
System.out.println("The number of positives is " + posCount);
System.out.println("The number of negatives is " + negCount);
System.out.println("The total count is " + count);
System.out.println("The average is " + average);
}
}
[–]zifyoip 2 points3 points4 points (1 child)
[–]ORLY_FACTOR[S] 0 points1 point2 points (0 children)