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 + " ");
}
Chat with our AI personalities
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);
}
}
}
public class forloop {
public static void main(String args[])
{
for(int i=50;i<=80;i++)
{
if(i%2==0)
{
System.out.println(i);
}
}
}
}
// 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);
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.
JAVA
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"); } }
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.
find even number in array
The Java console is a display of output sent by a Java program. This is similar to the MS DOS operating system.To print to the console, a programmer will type "println(text);" or "print(text);" depending is the programmer wants to make a new line after the text(println) or not(print).