» » » Basic Java Example Program to check even or add

1.Basic Java program to check even or add

  1. package com.BasicJavaProgramsExamples;
  2. import java.util.Scanner;
  3. public Class EvenOrOdd{ 
  4.  
  5. public static void main(String args[]) {
  6.  
  7. Scanner in= new Scanner(System.in);
  8. System.out.println("Please enter number to check even or odd");
  9.  
  10.     int n=in.nextInt();
  11.    
  12.          
  13. if(n%2==0){
  14.   System.out.println(+n" is even number");
  15. } else{
  16.  
  17. System.out.println(+n" is even number");
  18.  
  19. }
  20. }
  21. }

Output:


  1. Please enter number to check even or odd
  2. 4
  3. 4 is even number




2.Basic Java program to check even or add from 1 to 10

  1. package com.BasicJavaProgramsExamples;
  2. public Class EvenOrOdd{ 
  3.  
  4. public static void main(String args[]) {
  5.  
  6. for (int a=1; a<=10; a=a++){
  7.  if (a%2==0)
  8.     System.out.println(a+" is even");
  9. else
  10.     System.out.println(a+" is odd");
  11.  
  12. }   
  13. }
  14. }

Output:

  1. 1 is odd
  2. 2 is even
  3. 3 is odd
  4. 4 is even
  5. 5 is odd
  6. 6 is even
  7. 7 is odd
  8. 8 is even
  9. 9 is odd
  10. 10 is even

3.Basic Java program to check even or add from an array

  1. package com.BasicJavaProgramsExamples;
  2. import java.util.Scanner;
  3. public Class EvenOrOdd{ 
  4.  
  5. public static void main(String args[]) {
  6.  
  7. int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};
  8.  
  9. for (int a=0; a<=numbers .length; a=a++){
  10.  
  11.  if (numbers[i]%2==0)
  12.     System.out.println(numbers[i]+" is even number");
  13. else
  14.     System.out.println(numbers[i]+" is odd number");
  15.  
  16. }    

  17. }
  18. }

Output:


  1. 1 is odd number
  2. 2 is even number
  3. 3 is odd number
  4. 4 is even number
  5. 5 is odd number
  6. 6 is even number
  7. 7 is odd number
  8. 8 is even number
  9. 9 is odd number
  10. 10 is even number
 

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu