Write a javascript program to accept two numbers and perform addition of two numbers.
Answers
Answered by
6
Answer:
class addition
{
public static void main(String args[])
{
int a = 5;
int b = 7;
int add = a+b;
System.out.println("The sum of the numbers are: "+add):
}
}
OR
class addition
{
public static void main(int a, int b)
{
int add = a+b;
System.out.println("The sum of the numbers are: "+add):
}
}
The first one will not ask the user for input and the second one will ask the user for input. Both the programs are same.
I hope I could help you out.
Answered by
2
The given code is written in JavaScript.
var a=parseInt(prompt("Enter an integer.."))
var b=parseInt(prompt("Enter another integer.."))
var c=a+b;
alert("The sum of the numbers you entered is: "+c)
- The prompt() method creates a dialog box from where we can take the input as string.
- parseInt() function parses that string and returns the integer.
- The integers are now added and stored in a variable named c.
- Now, the value of the variable c is displayed using alert() function.
Attachments:
Similar questions