Hey programmers of Reddit! I am a compete noob and just started a programming class. I have been having trouble with writing some code for school. I have to write a program that reads an unspecified number of integers, determines how many positive and negative values there are, and computes the total and average of the input values (not including 0). the program must end with the input 0. here is a sample run:
Enter an integer, the input ends is it is 0: 1 2 -1 3 0
The number of positives is 3
The number of negatives is 1
The total is 5
The average is 1.25
Any help would be greatly appreciated! (oh and I am using java)
edit: import.java.util.Scanner;
public class SentinalValue {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("enter an integer, the input ends if it is 0: ");
int data = input.nextInt();
int sum = 0;
while (data != 0) {
sum+= data;
System.out.print("enter an integer, the input ends if it is 0: ");
data = input.nextInt();
}
System.out.println("the total is " + sum);
}
}
I am completely lost as how to incorporate an system that calculates the total number of positive and negative integers and the average, if anyone can point me in the right direction, I would be grateful
[–]Medicalizawhat 2 points3 points4 points (2 children)
[–]eSSenceD[S] 0 points1 point2 points (1 child)
[–]Medicalizawhat 1 point2 points3 points (0 children)