This is a code that I wrote and for some odd reason it doesn't count the number of inputted integers properly.
import java.util.Scanner;
public class IntegerCount
{
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 num = input.nextInt();
if ( num == 0 ){
System.out.println("No numbers were entered except 0");
}
else{
System.out.println("The number of integers is " + num);
}
}
}
If i were to enter lets say 9 numbers, it will say 2 numbers instead of 9. If i enter 25, it will say 500 instead of 25. The only time it works is if you enter a number like 0.
can someone help me with this?