-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Sum of Two given Numbers in Java
I made an implementation that calculates the Sum of Two given Numbers in Java
- Loading branch information
1 parent
ec8e11f
commit 12af650
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import java.util.*; | ||
|
||
public class SumOfTwoNumbers { | ||
public static void main(String[] args) { | ||
// Create a Scanner object to read input from the user | ||
Scanner sc = new Scanner(System.in); | ||
|
||
// Prompt the user to enter the first number | ||
System.out.print("Enter first number: "); | ||
int a = sc.nextInt(); // Read the first integer input | ||
|
||
// Prompt the user to enter the second number | ||
System.out.print("Enter second number: "); | ||
int b = sc.nextInt(); // Read the second integer input | ||
|
||
// Calculate the sum of the two numbers | ||
int sum = a + b; | ||
|
||
// Print the result to the console | ||
System.out.println("The sum is: " + sum); | ||
|
||
// Close the Scanner | ||
sc.close(); | ||
} | ||
} |