Just curious... I've got a snippet of code I'm trying to put together, and what I'm trying to get it to do is to print out the word "yes" exactly when i ends in the digit 4, or j ends in the digit 7, or both. I know my if statement is totally off, but I thought I'd give it a shot anyway. lol Doesn't hurt to try, even though I know I'm way off base on this one.

Here's what I've written up so far:

for (int i=0; i < 100; i++)
  for (int j=0; j < 100; j++)
    if (i == 4 && j == 7) 

System.out.println ("yes");

Many thanks, as always :)

Recommended Answers

All 3 Replies

Hmm, the only thing 'wrong' is that in your explanation you say "i == 4 OR j == 7" and in de condition of your if-statement you say AND instead of OR...

Hmm, the only thing 'wrong' is that in your explanation you say "i == 4 OR j == 7" and in de condition of your if-statement you say AND instead of OR...

Ah yes, I fixed it. Here I thought I was not even in the right ballpark. Good, at least I was on the right track afterall. *phew*

Just an unrelated side suggestion:
Always go ahead and use braces with your for() and if() blocks, even if they execute a single statement. Yes, it is unnecessary, but you will save yourself a lot of debugging headaches when one day you add another statement to block and can't figure out why your code isn't working right.
Trust me - you will do that one day. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.