From 12af65036edd16dfdd117b9822fd6bc2353b6e6d Mon Sep 17 00:00:00 2001 From: AhmadAnzar Date: Fri, 25 Oct 2024 07:25:12 +0530 Subject: [PATCH] Add Sum of Two given Numbers in Java I made an implementation that calculates the Sum of Two given Numbers in Java --- Java/SumOfTwoNumbers.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Java/SumOfTwoNumbers.java diff --git a/Java/SumOfTwoNumbers.java b/Java/SumOfTwoNumbers.java new file mode 100644 index 0000000..2f3d36c --- /dev/null +++ b/Java/SumOfTwoNumbers.java @@ -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(); + } +}