class count
{
public static void main(String args[])
{
int a=0;
int i;
int l=0;
int b=0;
int c=0;
for(i=1;i<=1000;i++)
c=i/10;
if(i%10==0)
{
l=l+1;
}
else if(c%10==0)
{
l=l+1;
}
System.out.println("no of zeros in this string is:"+l);
}}

this is my code...to calculate number of zero from 1 to 1000,,,,but i have an problem in that code piz tell me right code,,,,thanks in advance,,,,hi;;;
m new to programming so please tell me m writig a program in java to calculate number of zero from 1 to 1000 using loop but dont get output yet piz tell me the exact code;;;;;;what i was doing is as follow::

class count
{
public static void main(String args[])
{
int a=0;
int i;
int l=0;
int b=0;
int c=0;
for(i=1;i<=1000;i++)
c=i/10;
if(i%10==0)
{
l=l+1;
}
else if(c%10==0)
{
l=l+1;
}
System.out.println("no of zeros in this string is:"+l);
}}



piz help....thanks in advance,,,,,!1

Edited 6 Years Ago by peter_budo: Please do not use CODE SNIPPET to post your questions. Please use FORUM THREAD instead.

Okay, let's see. You want your code to print out, for each number from 1 to 1000, the number of zeros? So, for 1, it would give 0, for 10, it would give 1, for 200, it would give 2, and for 899, it would give 0, and so forth?

I don't think I understand your algorithm. Can you tell us, in English, how you want to go about it? Suppose you just want to tell me how many zeros are in each of these numbers. What would your code do for each of these inputs, if you got it working?

5
30
305
398
400

i cant understand what your program is
if u know telugu u ask in telugu also
else try to explain ur program much better than previous post
anyway, try this

class count
{
public static void main(String args[])
{
    int a=0;
    int i;
    int l=0;
    int b=0;
    int c=0;
    for(i=1;i<=1000;i++)
    {
        c=i/10;
        if(i%10==0)
        {
            l=l+1;
        }
        else if(c%10==0)
        {
            l=l+1;
        }
    }
    System.out.println("no of zeros in this string is:"+l);
}
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

class count
{
public static void main(String args[])
{
	int a=0;
	int i;
	int l=0;
	int b=0;
	int c=0;
	for(i=1;i<=1000;i++)
	{
		c=i/10;
		if(i%10==0)
		{
			l=l+1;
		}
		else if(c%10==0)
		{
			l=l+1;
		}
	}
	System.out.println("no of zeros in this string is:"+l);
}
}

Kishore - what do you get when you run this? Don't send us the whole thousand lines of output, but maybe a sample.

i dont get your program.
just i made simple modifications
u forgot to put braces for FOR loop, i made it
i really dont under stand what ur problem is

sir, i am trying to answer his question
i think he forget to put braces for FOR loop
so, i rectify that
i am already told I am not getting his question...
sir, please tell me i am not aligible for to help him ???????

Okay - kishore, you're right, that was a correction that needed to be made. Next time, you should identify the problem you're fixing, and how you're fixing it, so other people reading the thread know what you're posting and why.

Of course you're welcome to help correct the code, the more the merrier.

But, I think Norm and I were both trying to point out that your correction has a pretty major flaw in it, and that it still fails to correct a major flaw in the original code.

Your code will hang around a while, and then produce the line
no of zeros in this string is: n, where n is, I'm doing this in my head so I might be wrong, around 162?

Norm's point was, if you'd actually checked your fix you would have seen that you need to put the brace after the print statement, so it prints a result for each number from 1 to 1000, instead of the sum of all the zeros in the numbers in that range.

And when you'd done that, you'd have seen that l needs to be set to zero at the top of the loop or it'll keep a running tally of zeros rather than printing the number of zeros in each number.

Comments
+1 for patience & grooming forum newbies
This article has been dead for over six months. Start a new discussion instead.