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