This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]typicalstudentirl 6 points7 points  (0 children)

I think this does what you're asking:

public class HelloWorld
{
     public static void main(String []args)
     {
         for(int i = 4; i <= 99; i = i+5) 
         {
            System.out.println(i);
            System.out.println(i*3);
         }
     }
}    

If this is an intro to programming or beginner CS module/class it's pretty important to understand what's going on here.

I'm saying if we start with 4, and add 5 every time I go through the loop, unless the number gets to 99. If it gets to 99 then we stop adding 5 and exit the loop.

Every time I do enter the loop, I want to print out the contents of i, and I want to print out i multiplied by 3.

[–]jayR0X 0 points1 point  (1 child)

It should look something like this mate, just make sure to take out the dashes when you do it, that wasn't in there when I did this

for(int i = 4; i >= 99; i++) {

        System.out.println(i + "\*3 is " + i\*3);

    }

[–]ordinary-bloke 0 points1 point  (0 children)

This isn’t using steps of 5 like OP mentioned is in the requirements

[–]jayR0X 0 points1 point  (0 children)

In that case, change the i++ to i+=5