Monday, 14 March 2016

simple coding for addition in java

Java is simple language. Here is the simple coding to adding two numbers that are given already.

First, is to include the header file.

    |class adding
Here the adding is the class name. You can keep your desired classname. This should not be any keywords.
This is the main program.
First is to declare the void main then the declaration part. Then the execution segment.
   |public static void main(String args[])
   |int a,b,c;
   |a= 5;
   |c= a+b;
   |System.out.println("Sum of the given       number is "+c);
   | }
   | }
After typing the program in the notepad, save the file using an extension as .java
Open the command prompt. Type the name of the drive where you have saved the file. 
Then now to set the path. 
path = C:\jdk1.3\bin;
Now to compile the java program 
In our case its, adding so 


Any errors will be shown. If not the next line will be displayed. 
Now to run the file then. Type java filename.

java adding

Output will be 

C:\Documents and Settings\dcom358>H:



H:\>java adding
Sum of the given number is 12