Question: Please Help! Beginner Java Write a Java program that prompts the user for a string, extracts the integers from it, then displays the list of
Please Help! Beginner Java
Write a Java program that prompts the user for a string, extracts the integers from it, then displays the list of integers one line at a time.
Functional requirements
The program should first prompt the user for a single string of integers. The program must read the entire line of input. All integers are assumed to be positive, so the integers within the string will each be a sequence of consecutive digits. Integers are separated by any non-digits characters. For example, the string "aa123 4p56-7890" contains the integers 123, 4, 56, and 7890.
Next the program should display each integer on its own line. For example:
123 4 56 7890
Finally, the program should prompt the user, asking if he or she wants to parse another string. If the user response begins with an uppercase or lowercase 'y' the program starts over from the beginning, otherwise the program ends.
Non-Functional requirements
You must write and use a method intParse to break the string into a list of integers. Its heading is
public static int[] intParse(String s)
and it should return an array containing the integers extracted from the input string s. The method intParse should not have any side-effects. In particular, it should not print anything. The main method should use the array of integers returned by intParse to print the list of integers.
import java.util.Scanner;
public class Lab13
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Please enter a string of integers : ");
String userIn = input.nextLine();
intParse(userIn);
}
public static int[] intParse(String s)
{
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
