Wednesday, February 26, 2014

Program to list all the even numbers less than or equal to any given number in Java

Program: Write a program to list all even numbers less than or equal to the number n.  Take the value of n as input from user.

Code:

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;

  4. public class EvenNumber {

  5. /**
  6. * @param args
  7. * @throws IOException 
  8. * @throws NumberFormatException 
  9. */
  10. public static void main(String[] args) throws NumberFormatException, IOException {
  11. // TODO Auto-generated method stub
  12. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

  13. System.out.println("Enter no :");
  14. int no=Integer.parseInt(br.readLine());
  15. for(int i=0;i<=no;i++)
  16. if(i%2==0)
  17. System.out.println("Even No :"+i);
  18. }

  19. }

No comments:

Post a Comment