Monday, 14 March 2016

simple addition in java - user defined variable

Java is simple language. Here is the simple coding to adding two numbers that are user defined.

First, is to include the header file.

    |class add
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[])throws IOException

   |DataInputStream a = new DataInputStream(

   |int a,b,c;

   |System.out.println("Enter the first number:");


   |System.out.println("Enter the second number:");

   |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, add so 

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

java add

Output will be 
C:\Documents and Settings\dcom358>H:
H:\>java add

Enter the first number
Enter the Second number
Sum of two numbers is 55