Blogroll

This blog is created for education about engineering students.All the engineering students are get free downloadable books here. not only books and also different software also available here

2.c.sum of integers

c) Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all the integers (Use StringTokenizer class of java.util)

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
{
int ni=Integer.parseInt(br.readLine());
sum=sum+ni;
}
System.out.print("the sum is"+sum);
}
}

No comments:

Post a Comment

Total Pageviews