Program to add two numbers
-------------------------------------------------
Program:
import java.util.Scanner;
public class AddTwoNumbers {
public static void main(String[] args) {
// Create a Scanner object to read input from the user
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first number: ");
// Read the first number from the user
double num
#basicprogramsProgram to add two numbers by accepting input from the user:
----------------------------------------------------
Program:
import java.util.Scanner;
public class AddTwoNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Prompt the user to enter the first number
System.out.print("Enter the first number: ");
int num1 = input.nextInt();
// Prompt the user to enter the second number
System.out.print("Enter the second number: ");
int num2 = input.nextInt();
// Add the two numbers
int sum = num1 + num2;
// Display the result
System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum);
}
}
----------------------------------------------------
#basicprograms
----------------------------------------------------
Program:
import java.util.Scanner;
public class AddTwoNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Prompt the user to enter the first number
System.out.print("Enter the first number: ");
int num1 = input.nextInt();
// Prompt the user to enter the second number
System.out.print("Enter the second number: ");
int num2 = input.nextInt();
// Add the two numbers
int sum = num1 + num2;
// Display the result
System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum);
}
}
----------------------------------------------------
#basicprograms
👍1