Search code examples
javasequences

Java sequences print


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


Solution

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