Running program and entering -10,-6,-2,0 and it is stating that 0 is the highest integer. 0 should be the program
Running program and entering -10,-6,-2,0 and it is stating that 0 is the highest integer. 0 should be the program
exit and i did !=0 so it should be -2 and not 0. Can anyone help?
import java.util.Scanner;
class Apple{
public static void main(String[] args) {
int num,count=0,counteven=0,countodd=0,large=0,smallest=0,sum=0;
Scanner input = new Scanner(System.in);
System.out.println(“Input an integer”);
while ((num = input.nextInt()) != 0) {
if(num%2==0)
{ counteven++;}
if(num%2!=0)
{ countodd++;}
//comparing each time entered number with large one
if (num > large)
{
large = num;
}
//comparing each time entered number with smallest one
if (num < smallest)
{
smallest = num;
}
sum=sum+num;
count++;
}
float avg=sum/count;
System.out.println(“The smallest integer is ” + smallest);
System.out.println(“The largest integer is ” + large);
System.out.println(“Total number of integers entered is ” + count);
System.out.println(“Total odd numbers entered ” + countodd);
System.out.println(” Total even numbers entered ” + counteven);
System.out.println(“The average value is ” + avg);