Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Write a program to list all even numbers between two numbers 
 

Here you will learn to write a program for listing out all the even numbers between two numbers.

 

Write a program to list all even numbers between two numbers

                         

Java Even Numbers - Even Numbers Example in Java:
Here you will learn to write a program for listing out all the even numbers between two numbers. For this first create a class named AllEvenNum under the java.io package. Now use the try/catch exception to avoid any kind of input error. After this create a buffer class in which all the input data are stored and modified. Then give message as to "Enter number" in the System method. 

As we have to find out all the even numbers between 1 and the input number, define an integer variable 'num'. Now apply ParseInt method that parses the string character into decimal integer. Again apply for loop in which define an integer i=1 and i<=  num also with an increment operator. Then apply the if condition that i/2=0 i.e. to find even numbers which are divided by the integer 2. In the end apply the catch exception. 

Now and compile and run the program, and enter your desired number to get all even numbers between 1 and this numbers.       

Here is the code of the program:

import java.io.*;

class AllEvenNum{
  public static void main(String[] args) {
    try{
      BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter number : ");
      int num = Integer.parseInt(br1.readLine());
      System.out.println("Even Numbers:");
      for (int i=1;i <=num ; i++){
        if(i%2==){
          System.out.print(i+",");
        }
      }
    }
    catch(Exception e){}
    
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c file array class list ui lists method get name using this oo root example where to exam drive store

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

12 comments so far (
post your own) View All Comments Latest 10 Comments:

hey guys ive just started java programming due to my course at university, i was just wondering the past11 or so tutorials i have understood quiet clearly but once i saw this one ive become very confused, im not too sure where all these symbols such as br1.readline came across from...because the intro doesnt really help me with this coding tutorial. Any suggestions as to how i can overcome my problem? thanks much appreciated.

Posted by tommy on Thursday, 03.6.08 @ 16:59pm | #51698

I am not clear with concpt of buffered reader and writter. Can you explain me with some examples, how thery are buffereing in and out.

Posted by shenbagarajan on Wednesday, 02.6.08 @ 12:35pm | #47390

nice one

Posted by rama on Wednesday, 11.7.07 @ 13:10pm | #36254

nice 1..
but are there any other ways to read an input other than using buffers(keyboard input)??
i havnt com across any...

Posted by Balu on Saturday, 06.30.07 @ 18:37pm | #20443

I want to understand the concept of BufferedReader, InputStreamReader and Integer.parseInt.
would you tellme what is the meaning of Now apply ParseInt method that parses the string character into decimal integer

Posted by Rohan Shanker on Monday, 05.28.07 @ 13:57pm | #17523

tell me clear picture about the try Buffer.why it is used and in which condition we can use it
please.

Posted by ramesh on Tuesday, 04.3.07 @ 23:29pm | #13296

I want to understand the concept of BufferedReader, InputStreamReader and Integer.parseInt. What is the significance in the code and is cos of these lines that you imported java.io...I need an immediate response to this cos dats wat I need to understand before I go on to the next step

Posted by Rufus on Wednesday, 03.14.07 @ 14:41pm | #11676

sir
would you tellme what is the meaning of Now apply ParseInt method that parses the string character into decimal integer
THANKS

Posted by w/brhan on Friday, 03.2.07 @ 13:19pm | #10204

A simple but superb example. Thanks
Kim Tran

Posted by Kim Tran on Thursday, 02.1.07 @ 20:03pm | #5251

thanks it helped a lot. am new to programming at the age of 33,i never use to like it,cos of problem solving, but now hv no option.

EXCELLENTE

Posted by abcdef on Wednesday, 01.31.07 @ 00:31am | #4756

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.