Computer Science, asked by talawatjaisree, 10 months ago

write a program to add three numbers​

Answers

Answered by stylishtamilachee
7

Answer:

public class Test

{

void myMethod( )

{

int num1, num2, num3, sum ;

num1 = 250 ;

num2 = 100 ;

num3 = 350 ;

sum = num1 + num2 + num3 ;

System.out.println(" 3 given numbers are: ");

System.out.println( num1 ) ;

System.out.println( num2 ) ;

System.out.println( num3 ) ;

System.out.println( " Sum = " + sum ) ;

}

}

Output:

3 given numbers are:

250

100

350

Sum = 700

Java:

Java is a popular third-generation programming language, which can be used to do any of the thousands of things that a computer software can do. With the features it offers, Java has become the language of choice for internet and intranet applications.

Answered by AbhijithPrakash
8
  1. ## I'm using Python language.
  2. ## This is a simple question so let's add some functions.
  3. ## For defining a function we use "def <name_of_function>():"
  4. def Sum(): ## I'm naming the function Sum().
  5.    SUM = a[0]+a[1]+a[2] ## Taking a variable SUM for storing the added values.
  6.    print ("The sum of {0}, {1} and {2} is {3}.".format(a[0],a[1],a[2],SUM)) ## This will print the last line for the code.
  7. ## I'm going to create 2 lists a, and b.
  8. a=[0,0,0] ## This list is having temporary values. The value will change in the for loop.  
  9. b=["first","second","third"]
  10. for i in range(0,3): ## for loop for asking the numbers that is to be added.  
  11.    a[i]=int(input("Enter the {} number : ".format(b[i])))  
  12. Sum() ## This is used to call the function.  
Attachments:
Similar questions