Answer:
In Java:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<String> Strs = new ArrayList<String>(); ArrayList<Integer> Ints = new ArrayList<Integer>();
String datapoint;
System.out.print("Data point (0 to quit): ");
datapoint = input.nextLine();
while(!"0".equals(datapoint)){
System.out.println("Data point: "+datapoint);
String[] datapointSplit = datapoint.split(", ");
Strs.add(datapointSplit[0]);
Ints.add(Integer.parseInt(datapointSplit[1]));
System.out.print("Data point (0 to quit): ");
datapoint = input.nextLine(); }
System.out.println("Strings: "+Strs);
System.out.println("Integers: "+Ints);
}}
Step-by-step explanation:
In Java:
Declare string and integer array lists
ArrayList<String> Strs = new ArrayList<String>(); ArrayList<Integer> Ints = new ArrayList<Integer>();
Declare datapoint as string
String datapoint;
Prompt the user for data point (An entry of 0 ends the program)
System.out.print("Data point (0 to quit): ");
Get the data point
datapoint = input.nextLine();
This is repeated until an entry of 0 is entered
while(!"0".equals(datapoint)){
This prints the datapoint
System.out.println("Data point: "+datapoint);
This splits the datapoint to 2
String[] datapointSplit = datapoint.split(", ");
This adds the string part to the string array list
Strs.add(datapointSplit[0]);
This adds the integer part to the integer array list
Ints.add(Integer.parseInt(datapointSplit[1]));
Prompt the user for another entry
System.out.print("Data point (0 to quit): ");
datapoint = input.nextLine(); }
Print the string entries
System.out.println("Strings: "+Strs);
Print the integer entries
System.out.println("Integers: "+Ints);