Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all the integers - C C++ Java Programs - Examples

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Monday, October 10, 2011

Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all the integers


Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all the integers 


import java.io.*;
class sum
{
public static void main(String args[])throws IOException


{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,n,sum=0;
System.out.print("enter the no of elements");
n=Integer.parseInt(br.readLine());
System.out.print("the elements are");
for(i=0;i<n;i++)
{
int ni=Integer.parseInt(br.readLine());
sum=sum+ni;
}
System.out.print("the sum is"+sum);
}
}

No comments:

Post a Comment