Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Help! Beginner Java Write a Java program that prompts the user for a stri

ID: 3866737 • Letter: P

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 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)

{

}

}

Explanation / Answer

Note:


Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

_______________________

Lab13.java

import java.util.Scanner;

public class Lab13 {
public static void main(String[] args) {


//Scanner object is used to get the inputs entered by the user
Scanner input = new Scanner(System.in);

//Getting the String entered by the user
System.out.println("Please enter a string of integers : ");
String userIn = input.nextLine();

//Calling the method by passing the String as arguement
int arr[] = intParse(userIn);

//Displaying the array elements
for (int i = 0; i < arr.length; i++) {
if (arr[i] != -1) {
System.out.print(arr[i]);
} else {
System.out.println();
}
}
}

//This method will extract the integers and populate them into an array
public static int[] intParse(String s) {
int arr[] = new int[s.length()];
int k = 0;
for (int i = 0; i < s.length(); i++) {
if (Character.isDigit(s.charAt(i))) {
arr[i] = Character.getNumericValue(s.charAt(i));
k = 0;
} else {
k++;
}
if (k == 1) {
arr[i] = -1;
}

}
return arr;
}
}

______________________

Output:

Please enter a string of integers :
aa123 4p56-7890

0123
4
56
7890


_____________Could you rate me well.Plz .Thank You