0

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 :)

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Ezzaral
0

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...

0

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*

0

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. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.