2 Replies - 6600 Views - Last Post: 23 April 2012 - 07:03 AM Rate Topic: -----

#1 imckinn40  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-March 12

I'm lost

Posted 23 April 2012 - 06:58 AM

Write a for loop that prints in ascending order all the positive integers less than 200 that are divisible by both 2 and 3, separated by spaces. I was told my _stdout is wrong and it's at execution. I have:

int i;

for (i=0; i<200; i++)
{
if(i%2==0 && i%3==0)
{
System.out.println();
}
}


I'm working with myprogramminglab, everything is provided and I have to finish with this but I think something is wrong with my ending.

Is This A Good Question/Topic? 0
  • +

Replies To: I'm lost

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: I'm lost

Posted 23 April 2012 - 07:02 AM

You don't print out anything at the moment, just a blank line. You want to print the variable 'i' -

System.out.println(i);


From what I gather from the question however, it wants you to print out each number on the same line seperated by spaces.

So instead of System.out.println() which prints out a line return and will look like

num
num
num
num
num

You probably want

num num num num num

Check out the System.out.print() method which doesn't print a line return.

This post has been edited by Ryano121: 23 April 2012 - 07:03 AM

Was This Post Helpful? 1
  • +
  • -

#3 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: I'm lost

Posted 23 April 2012 - 07:03 AM

What do you mean by problem? What is happening that shouldn't be? Should something be printed, or?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1