genrate a java code for addition of two numbers
Sure! Below is a simple Java program that demonstrates how to add two numbers:
```java
import java.util.Scanner;
public class Addition {
public static void main(String[] args) {
// Create a Scanner object to read input
Scanner scanner = new Scanner(System.in);
// Prompt the user for the first number
System.out.print("Enter the first number: ");
double num1 = scanner.nextDouble();
// Prompt the user for the second number
System.out.print("Enter the second number: ");
double num2 = scanner.nextDouble();
// Perform the addition
double sum = num1 + num2;
// Display the result
System.out.println("The sum of " + num1 + " and " + num2 + " is: " + sum);
// Close the scanner
scanner.close();
}
}
```
### How to Run the Program
1. Copy the above code into a file named `Addition.java`.
2. Open a command prompt or terminal window.
3. Navigate to the directory where you saved the file.
4. Compile the Java file using the command:
```
javac Addition.java
```
5. Run the compiled program using the command:
```
java Addition
```
6. Follow the prompts to enter two numbers, and the program will display their sum.
Feel free to modify the program as needed!