Write a method called powersOfTwo that prints the first 10 powers of 2 (starting with 2). The method takes no parameters and doesn't return anything.

What will be an ideal response?


```
public void powersOfTwo()
{
int base = 2;
for (int power = 1; power <= 10; power++)
System.out.println(Math.pow(base,power));
}
Alternate answer:
public void powersOfTwo()
{
int num = 2;
for (int power = 1; power <= 10; power++)
{
num *= 2;
System.out.println(num);
}
}
```

Computer Science & Information Technology

You might also like to view...

Which of the following is the correct statement to return JAVA?

a. toUpperCase("Java") b. "Java".toUpperCase("Java") c. "Java".toUpperCase() d. String.toUpperCase("Java")

Computer Science & Information Technology

Data in a worksheet is NOT always formatted in a way you can use it

Indicate whether the statement is true or false

Computer Science & Information Technology

Modular development does not necessarily lead to a higher-quality product.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

In the context of data processing, a C program is not usually considered data, and the term file, or data file, is typically used to refer only to external files that contain the data used in a C program.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology