write a program to add three numbers
Answers
Answered by
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
8
- ## I'm using Python language.
- ## This is a simple question so let's add some functions.
- ## For defining a function we use "def <name_of_function>():"
- def Sum(): ## I'm naming the function Sum().
- SUM = a[0]+a[1]+a[2] ## Taking a variable SUM for storing the added values.
- 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.
- ## I'm going to create 2 lists a, and b.
- a=[0,0,0] ## This list is having temporary values. The value will change in the for loop.
- b=["first","second","third"]
- for i in range(0,3): ## for loop for asking the numbers that is to be added.
- a[i]=int(input("Enter the {} number : ".format(b[i])))
- Sum() ## This is used to call the function.
Attachments:
Similar questions
Math,
5 months ago
French,
5 months ago
CBSE BOARD X,
10 months ago
Math,
10 months ago
English,
1 year ago