Java is simple language. Here is the simple coding to adding two numbers that are given already.
First, is to include the header file.
First, is to include the header file.
|import java.io.*;
|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;
|b=7;
|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
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
javac filename.java
In our case its, adding so
javac adding.java
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:\>path=C:\jdk1.3\bin;
H:\>javac adding.java
H:\>java adding
Sum of the given number is 12
No comments:
Post a Comment