Question: help me explain the code line by line import java.util.Scanner; public class program { public static void main(String[] args) { Scanner scan = new Scanner(System.
help me explain the code line by line
import java.util.Scanner;
public class program {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
float total =0;
double average = 0.0;
int numOfNeg = 0;
int numOfPos = 0;
int numOfValues = 0;
int value;
System.out.print("Enter an integer, the the input" + "ends if it is 0:");
value = scan.nextInt();
while (value != 0) {
if (value > 0) {
numOfPos++;}
else if (value < 0) {
numOfNeg++;}
numOfValues++;
total += value;
value = scan.nextInt();
if (numOfValues == 0) {
System.out.println("Number are entered" + " except 0");}
else {
System.out.println("The number of positives" + " is ");
System.out.println("The number of negatives" + " is ");
System.out.printf("The total is %.1f ", total);
System.out.printf("The average is %.2f ", average);
}
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
