Prompt a user to enter a series of integers separated by


Question :

Prompt a user to enter a series of integers separated by spaces and accept the input as a String. Display the list of integers and their sum.

Save the file as SumIntegersInString.java.

You have tried the following code, but it just runs continuously with no opportunity for input.

import java.io.*;

import java.util.Scanner;

class SumIntegersInString
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
String input = in.nextLine();
int sum = 0;
for(String value : input.split(" "))
{
System.out.print(value + " ");
sum += Integer.parseInt(value);
}
System.out.println("Sum:" + sum);

}
}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Prompt a user to enter a series of integers separated by
Reference No:- TGS02903679

Expected delivery within 24 Hours