(2) Write a program to store 10 elements through user input and sum the array of elements in to a word
1
Expert's answer
2011-08-07T07:18:34-0400
import java.io.*;
public class Task9 { public static void main(String[] args) throws IOException { & // Preparing the stream & BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
& // reading the elements inputed by user & String[] elements = new String[10]; & for (int i = 0; i < 10; i++) & { & System.out.print("Enter the element (string of the symbols): "); & elements[i] = bReader.readLine(); & }
& // Summing the elements into a word: & String word = new String(); & for (int i = 0; i < 10; i++) & word += elements[i]; & System.out.print("\n\nThe sum of the array elements:\n" + word); } }
Comments
Leave a comment