The return type is void and there is one input parameter and I am trying to use a while loop to print out how many of a certain number there is an the input integer.
So as an example int i = 32001; then I want too know how many 0's there are in the int and the output would be 2 cause there's only two 0's in that int.
My code below for some reason only outputs 0 and I don't know why. Could someone pls fix or help.
And please don't use any power tools or certain methods that do the work for you and you can use for loop or while loop.
public class loopPrr
{
public void howMany0(int i){
int n = 0;
int howmany = 0;
char z = '0';
while(i <= 0){
++i;
if(i == z){
howmany++;
}
}
System.out.println(howmany);
}
public static void main(String args[]){
loopPrr n = new loopPrr();
n.howMany0(32001);
}
}
Aucun commentaire:
Enregistrer un commentaire