Reputation: 65
How do i write simpla Java sequence in my editor (using notepad++)?
I am familiar with the basics but having trouble getting this one to print in my cmd.
int a = 1; a = a + a; a = a + a; a = a + a; ...
Upvotes: 1
Views: 1598
Reputation: 129507
Try this:
int a = 1;
for (int i = 0 ; i < MAX_PRINTS ; i++) {
System.out.println(a);
a *= 2;
}
Or if you want to print until a certain value is reached:
int a = 1;
while (a <= MAX_VALUE) {
System.out.println(a);
a *= 2;
}
Upvotes: 1
Reputation: 26
This should be what your looking for.
public static void main(String[] args)
{
int startValue = 1;
int numberOfAdditions = 10;
int currentValue = startValue;
for(int i = 0;i<numberOfAdditions;i++)
{
//do opperations here
currentValue = currentValue+currentValue;
//print out value
System.out.println(currentValue);
}
}
Upvotes: 1