Computer Science, asked by albinmathew8012, 11 hours ago

Write a javascript program to accept two numbers and perform addition of two numbers.

Answers

Answered by AreetraSircar
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 anindyaadhikari13
2

\texttt{\textsf{\large{\underline{Solution}:}}}

The given co‎‎de is written in JavaScript.

\rule{300}{2}

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)

\rule{300}{2}

\texttt{\textsf{\large{\underline{Explanation}:}}}

  • The prompt() method creates a dialog box from where we can take the input as string.
  • parseInt() fu‎nction 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() fu‎nction.
Attachments:
Similar questions