answersLogoWhite

0


Best Answer

final int limit = 1000000;

// Print evens...

for(int i = 0; i <= limit; i += 2) {

System.out.print(i + " ");

}

// Print odds...

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

System.out.print(i + " ");

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

public class Test {

public static void main(String[] args){

for(int i = 0; i<100; i++){

if(i%2 == 0){

System.out.println(i);

}

}

}

}

OR

public class Test {

public static void main(String[] args){

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

System.out.println(i);

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

public class forloop {

public static void main(String args[])

{

for(int i=50;i<=80;i++)

{

if(i%2==0)

{

System.out.println(i);

}

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

// finds this sum in range (1, 100]

int sum = 0;

for(int i = 2; i < 101; i+=2) {

System.out.println("Adding : " + i);

sum += i;

}

System.out.println("Sum : " + sum);

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Use a for loop, and increment two at a time. Something like this:

sum = 0;

for (i = 1, i <= 100, i += 2)

sum += i;

Explanation: "i" starts at 1, the loop continues running (and adding to the sum) while i is less than or equal to 100, and i is incremented two at a time.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: To print even numbers in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Q2 Write a program to print even numbers between 10 and 50?

You can use int i; for (i = 10; i &lt;= 50; i += 2) {//print i} as a program to print even numbers between 10 and 50.


What Program that will display the even numbers in data structures and algorithms?

JAVA


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 in BlueJ to print lucky numbers?

To print lucky numbers in java, you must give the following program: class example { static public void main(String[] args) { System.out.println("Lucky number is your favourite number which is your DOB"); } }


Print sum of first ten even numbers?

It is 110.


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


Write an algorithm to print sum of all even numbers?

Start print "the sum of all even numbers is infinite" end


What is java program on computers?

#!/usr/bin/perl print 'java program';


How can you print a table of 5 in java by getting values from user?

look at the print


Java code to print prime numbers from 1 to 10?

System.out.println("2, 3, 5, 7"); There are so few you dont need to calculate it


How do you print a string 5 times in java?

For(int I = 0: I &lt; 5; i++) { System.out.println(" print this " + I ); }


What is Systemerr in java?

System.err is much like System.out, except instead of going to standard output, it returns a stream to standard error. According to the Java API, you should use this to print out error messages directly to the user even if you have redirected System.out to print to a file or other stream.