Simple programs in JAVA

JAVA is dynamic programming language. It is capable of making simple program to complex. We can make simple program of add, even numbers, odd numbers.

First program of adding two numbers in JAVA

Add.java

public class Add {

    public static void main(String[] args) {
        int a=5;
        int b=2;

        int result=a+b;

        System.out.print("Additon of a and b :"+result);

    }

}

Second program of subtraction two numbers in JAVA

Subtract.java

public class Subtract {

    public static void main(String[] args) {
         int a=5;
         int b=2;

         int result=a-b;

         System.out.print("Subtraction of a and b :"+result);

    }

}

Third program of print even numbers in JAVA

EvenNumber.java

public class EvenNumber {

    public static void main(String[] args) {
        for(int i=0;i<=10;i++)
         {
          if((i%2)==0)
          {
           System.out.println("Even number  :"+i);
          }
         }
    }
}

Forth program of print odd numbers in JAVA

OddNumber.java

public class OddNumber {

    public static void main(String[] args) {
        for(int i=0;i<=10;i++)
         {
          if((i%2)!=0)
          {
           System.out.println("Odd number  :"+i);
          }
         }
    }
}

Tags:

Bookmark  

 

One Response to “Simple programs in JAVA”

  1. venkatesh says:

    u r providing exellent results and a small request from my side is give alternate solutions for a particular task.
    thank u

Leave a Reply

Security Code:

 

  Random Post