Write a program to input n numbers using for loop. When the users enters zero, then display the sum of the numbers you entered and count how many numbers you entered. Use scanners. Best answer I will mark as brainliest...
Answers
import java.util.*;
public class program_brainly
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int a[] = new int[50];
int n,s=0;
System.out.println("Enter the value of n:");
n=in.nextInt();
System.out.println("Enter" +n+ "numbers:");
for(int i=0; i<n; i++)
{
a[i] = in.nextInt;
}
for(int i=0; i<n;i++)
{
s=s+a;
}
System.out.println("Sum of the numbers you entered =" +s);
System.out.println("total numbers you entered=" +n);
}
}
we need to use array as we are taking more than one number as input in once and finding its sum..