write a program in java using loop to find the middle digit of a number
Answers
Answer:
Explanation:
Java Program Sum Of N Numbers | 4 Simple Ways
in Java Programs Comments Offon Java Program Sum Of N Numbers | 4 Simple Ways
Java program to calculate the sum of N numbers using arrays, recursion, static method, using while loop. Here is the complete Java program with sample outputs. You can learn more tutorials here and Java interview questions for beginners. With the following program, you can even print the sum of two numbers or three numbers up to N numbers.
How to calculate?
Just summing of two numbers or three numbers or up to N numbers.
Sum Of N Numbers Program
1. Using Arrays
[wp_ad_camp_3]
Here is the sample program with output sum of two numbers program or three numbers. check it out
How this program works: we are using arrays to store the values first. From a user input point of view, let’s assume you need to sum five numbers. Say 5: Now the next step is to enter those numbers in a series order. Once it was done, the program automatically adds all your two numbers or three numbers like up to N numbers.
check out the sample output so that you will get an Idea:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Scanner;
class sum
{
public static void main(String arg[])
{
int n,sum=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter how many numbers you want sum");
n=sc.nextInt();
int a[]=new int[n];
System.out.println("enter the "+n+" numbers ");
for(int i=0;i<n;i++)
{
System.out.println("enter number "+(i+1)+":");
a[i]=sc.nextInt();
}
for(int i=0;i<n;i++)
{
sum+=a[i];
}
System.out.println("sum of "+n+" numbers is ="+sum);
}
}
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
enter how many numbers you want sum
5
enter the 5 numbers
enter number 1:
32
enter number 2:
12
enter number 3:
43
enter number 4:
212
enter number 5:
23
sum of 5 numbers is =322
2. Using Recursion
Here is another method using recursion: A recursion is a function call itself. Here is the sample program to print the sum of N numbers in J
Answer:
can you please tell its variable description
if anyone reads mine message please answer it