C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Add two numbers in Java
WhatsApp
Kiran Thakur
5y
6.4
k
0
0
25
Blog
Add two numbers in Java
Step 1:
Let's open a notepad and write the following code.
//Code
class
demo {
public
static
void
main(String arg[]) {
int
a =
10
, b =
20
, c =
0
;
c = a + b;
System.out.println(
"sum of two no is :"
+ c);
}
}
Step 2:
Name it as "ab.java" and save the file on any location. I saved at "
C:\app
".
Step 3:
Open command prompt (Press Window + R and write cmd and hit OK).
Step 4:
Go to "C:\app" by using command prompt
Step 5:
Now write the following code for checking my java file is compiling or not.
javac ab.java
My java program compiled successfully.
Step 6:
Write the following code in command prompt. Press enter and see the output.
java demo
// demo is a class name that is written in my ab.java file.
Output
Happy Coding.
Add two numbers in Java
Up Next
Swap two numbers without using third variable in java
Ebook Download
View all
Solutions Manual to Objects First with Java – A Practical Introduction using BlueJ
Read by 1.8k people
Download Now!
Learn
View all
Membership not found