answersLogoWhite

0

Like this:

int sum = 0;

for(int i = 1; i<=100; i+=2){

sum+=i;

}

The "for" loop starts the counter i at 1, continues while it is less than or equal to 100, and increments it by 2 at a time.

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

How do you write a program in java to read ten numbers and print sum of ten integers?

Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


What time of loop is used when you know how many times the loop instructions should be processed?

It's best to use a for loop.For example, if you want 10 iterations:for (int i = 1; i


How do you exit in nested loop in java?

You may exit a nested loop in Java using a break with a label for the outer loop.


How do you print non-prime numbers in java?

Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.


Hoe can you write a programme to claculate 1 plus 2 plus 3..100?

You add the numbers in a loop. Here is an example in Java:int sum = 0;for (int i = 1; i


What are functions in JAVA?

for loop function


How can you use the "break" statement in Java to prematurely exit a "for" loop?

In Java, you can use the &quot;break&quot; statement within a &quot;for&quot; loop to exit the loop prematurely. When the &quot;break&quot; statement is encountered, the loop will immediately stop executing and the program will continue with the code after the loop.


Write a for next loop for even numbers beginning at 10 and ending at 50?

int i;for (i=10; i


When is Iteration used in a Java program?

in a loop


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


How can you repeatedly execute a code in java script?

1) use for loop 2) do while loop