Ok I am writing a program that has to use for and while loops. This program will have to output a list of even numbers between 1-100. Is this program correct I wrote or what does it need?

public class loops
{
  public static void main(String args[]){
    var x = 0
      while (x<=100){
      document.write(x);
      x++;
    }
    {
      for(int x = 2; x>0; x++)
      {
        System.out.println(x);
      }
    }
  }
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

So this is the same exact question you posted in a different thread 6 hours ago, that I answered then? May I ask why you would ignore my advice in that thread, then post another one with the same question instead? Nobody is going to do your homework for you. And now that you decided to ignore my advice without the courtesy of a response, I won't give you any more help. Although you might want to clarify for anyone else who wishes to help you why you need to use two loops to do a task when one loop would suffice. (And why my previous suggestion of using the modulus % operator wasn't good enough).

Edited 6 Years Ago by BestJewSinceJC: n/a

Thank you this is not homework. I am a teacher who has no experience with this. I am trying to help another child out for your information, so dont get so rude with me!

Yeah, down vote me; that'll teach me. I don't think I'm being rude by expecting you to not create multiple threads on the same topic, especially without acknowledging the help you've already received or making an attempt to solve the problem on your own. As a teacher, you should understand that it is courteous to acknowledge the help you've received, regardless of whether or not you think it was helpful. It has nothing to do with whether or not this is homework, it has to do with manners.


P.S. why are you helping a student with a programming question if you obviously don't know any programming yourself? I can't imagine that any programming teachers don't know how to use a for loop. .

Edited 6 Years Ago by BestJewSinceJC: n/a

Comments
Only the really good ones don't use for-loops...duh ;)

As a teacher I want multiple peoples openions on a topic. I do not go from what one person tells me. If you can accept the fact I wanted someone to check what I had wrote I DON'T CARE! Maybe I never studied Java real hard that don't matter atleast I'm trying to help someone out.

Creating another thread without responding to the previous one tells me you didn't appreciate the time people in the previous thread gave towards helping you. And after posting a question, from our perspective you're not the one trying to help someone out, the people who respond to your threads are trying to help you.

Also, I could go on a rant here about why (including programming constructs, spelling, grammar, and lack of appreciation for other people's time) but lets just say I don't believe for a minute you are actually a teacher and leave it at that. I'll stop posting in your thread now, so my apologies for clogging it up.

I don't care what you think. I teach math not english or programming so question me all you want.

Comments
Unappreciative of help, argumentative, and thinks being a 'teacher' excuses bad manners. Shame.

After looking at the other post with the same question, please eshirley answer me this.

Why didn't you post the code you posted here to that thread. In general why didn't post the entire first post of this thread to that. It would have been acceptable. You asked for a question and depending on the answer you got at that thread, you came up with that piece of code and you wanted to ask a question about it.

Please, I am waiting for the response.


Also did you run the code and what results did you get. Don't post code and ask if it is correct, when you can easily run it for yourself and see if it does what you want.

And one last thing.
You must understand that all forums have rules which anyone must follow when posting to them. And in any forum when you break the rules you will be asked to follow them.
One of them is not to make 2 threads that ask the same thing. It might be mistaken for spamming. So don't get upset when you break the rules that you accepted when registering here.

And on a more personal note, your question sounded like you wanted to see if the code works so you can give it to the student that asked for help. That is against the forum rules and as a teacher you shouldn't been doing this. You should been teaching the student how to write that code and if you say that you are not a programmer and that is the best you can do, you shouldn't been doing it. The kid needs a programmer to teach him not a math teacher to give him solutions.

And if you make it this far, please can you at least answer my first question?

After looking at the other post with the same question, please eshirley answer me this.

Why didn't you post the code you posted here to that thread. In general why didn't post the entire first post of this thread to that. It would have been acceptable. You asked for a question and depending on the answer you got at that thread, you came up with that piece of code and you wanted to ask a question about it.

Please, I am waiting for the response.


Also did you run the code and what results did you get. Don't post code and ask if it is correct, when you can easily run it for yourself and see if it does what you want.

And one last thing.
You must understand that all forums have rules which anyone must follow when posting to them. And in any forum when you break the rules you will be asked to follow them.
One of them is not to make 2 threads that ask the same thing. It might be mistaken for spamming. So don't get upset when you break the rules that you accepted when registering here.

And on a more personal note, your question sounded like you wanted to see if the code works so you can give it to the student that asked for help. That is against the forum rules and as a teacher you shouldn't been doing this. You should been teaching the student how to write that code and if you say that you are not a programmer and that is the best you can do, you shouldn't been doing it. The kid needs a programmer to teach him not a math teacher to give him solutions.

And if you make it this far, please can you at least answer my first question?

Im not getting caught up in all this stuff. But I had answered a nearly similar post not too long ago. Look up the posts that I have answered and you should find the answer. Otherwise the basic calculation is:

if(number % 2 == 0){
System.out.println(number+ " is even");
else {
System.out.println(number+ " is odd");
}

Of course it has to be placed in a for loop to test all the numbers between 0 and 100

This article has been dead for over six months. Start a new discussion instead.