Answer to Question #3479 in Java | JSP | JSF for Y mukundareddy
Question #3479
(2) Write a program to store 10 elements through user input and sum the array of elements in to a word
Expert's answer
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);
}
}
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);
}
}
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment