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 + " ");
}
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.
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).
find even number in array
You can use int i; for (i = 10; i <= 50; i += 2) {//print i} as a program to print even numbers between 10 and 50.
JAVA
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.
It is 110.
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"); } }
Start print "the sum of all even numbers is infinite" end
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.
#!/usr/bin/perl print 'java program';
look at the print
System.out.println("2, 3, 5, 7"); There are so few you dont need to calculate it
For(int I = 0: I < 5; i++) { System.out.println(" print this " + I ); }
find even number in array