# EVEN NUMBERS

EVEN NUMBERS
1 Answer(s)      7 years ago
Posted in : Java Interview Questions

July 23, 2009 at 3:17 PM

Hi Friend,

Try the following code:

class EvenNumbers{
public static void main (String args[]){
String evenNo = "";
int counter = 0;
System.out.println("Even Numbers are:" );
for (int i = 1; i <=20; i++){
if (i % 2 == 0) {
evenNo += i + " ";
counter++;
if (counter == 5) {
evenNo += "\n";
counter = 0;
}
}
}
System.out.println(evenNo);
}
}

Thanks

Related Tutorials/Questions & Answers:
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi, You function will take 2 numbers and the find the even numbers between
EVEN NUMBERS - Java Interview Questions
EVEN NUMBERS  i want program of even numbers?i want source code plz reply?  Hi Friend, Try the following code: class EvenNumbers... counter = 0; System.out.println("Even Numbers are:" ); for (int i
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer... prints out the even numbers between the range of 100 and 200 and then determine
How to list even numbers between 1 and 100?
How to list even numbers between 1 and 100?  Hi, I Java to check if a number is even? How to list even numbers between 1 and 100? Thanks   Hi, If number is divisible by 2 then its even number. Suppose you have
Java write even numbers to file
Java write even numbers to file In this section, you will learn how to write the even numbers to file. By using the PrintWriter class, you can write any type... have used print() method to store the even numbers to the file. println
Write a program to list all even numbers between two numbers
Write a program to list all even numbers between two numbers       Java Even Numbers - Even... all the even numbers between two numbers. For this first create a class named
write an application that print out the even numbers between the range 100-200
write an application that print out the even numbers between the range 100-200   write an application that print out the even numbers between... and determine the even numbers between them. class EvenNumbers { public static
Calculate sum of even and odd numbers in Java
Calculate sum of even and odd numbers In this section, you will learn how to read the file that contains even and odd numbers and calculate their sum separately. To do this, first of all, we have found all the even and odd numbers from 1
Check whether highest number is even or odd
Check whether highest number is even or odd In this section, you will learn how to check highest number between the two numbers and then determine whether it is odd or even. For this, we have taken two integer variables num1 and num2
odd and even
odd and even  how can i make a program of even and odd using case...); System.out.println("Enter Numbers: "); int arr[]=new int[10]; for(int i=0;i<...{ System.out.println(); System.out.println("1 Display Even"); System.out.println("2
Check even or odd number.
is used for inputting number. Even numbers are those numbers, which are divisible...Check even or odd number.  How to check given number is even or odd?   Simple if it is devided by 2 it is even and if not if is Odd
Even and odd functions in java
"); } } } Description : Number which is divisible by 2 is called even numbers...Even and odd functions in java  Even and odd functions in java  ...); int number; System.out.println("Input any number to check even
automorphic numbers
automorphic numbers  how to find automorphic number in java   Hi Friend, Pleas visit the following link: Automorphic numbers Thanks
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String...=input.nextInt(); list.add(num); } System.out.println("Numbers
PRIME AND EVEN AND ODD - Java Interview Questions
PRIME AND EVEN AND ODD  how to write prime numbers?i want source code? how to write even numbers? i want source code? how to write odd numbers ?i... + " "; } } } System.out.println(primeNo); } } 2) Following code displays Even and Odd numbers
Prime Numbers
Prime Numbers  Create a complete Java program that allows the user to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents
JSTL - check odd/even number - JSP-Servlet
JSTL - check odd/even number  How do i create a JSTL program to generate random numbers and to check whether they are odd/even and print "this is an even (odd) number and it is in between so and so number? e.g. the random number
Rational Numbers
Rational Numbers   Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer values, a and b, where b is not zero. The class has attributes for the numerator
Numbers pyramid
Numbers pyramid  Hi sir, Can you please tell me how to output this using nested for loops? 1 2, 1 1, 2, 3 4, 3, 2, 1 1, 2, 3, 4, 5 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7 8, 7, 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 9, 8
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
even more circles - Java Beginners
even more circles  Write an application that compares two circle objects. ? You need to include a new method equals(Circle c) in Circle class. The method compares the radiuses. ? The program reads two radiuses from the user
Hexadecimal numbers multiplication  Sir, I have to multiply 128 bit hexadecimal numbers. Do u have any logic for this?? The numbers are like ab7564fa342b5412c34d9e67ab341b58
Addition of two numbers
Addition of two numbers  addition of two numbers
defining numbers in Java Script
defining numbers in Java Script  Explain about defining numbers in Java Script
multiply of 100 digits numbers
multiply of 100 digits numbers  multiplying 100 digits numbers to eachother
numbers divisible by 5 and 6
numbers divisible by 5 and 6  Find the first ten numbers which are greater than Long.MAX_VALUE divisible by 5 and 6
print the sum of even number from 1 to 100
print the sum of even number from 1 to 100  how to print the sum of even number from 1 to 100 using for loops? Thanks