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

有帮助吗?

解决方案

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);
    }
}

其他提示

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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top