148k views
5 votes
Then create a new Java application called "StringSlicer" (without the quotation marks) that uses methods to:

Get a String from the user at the command line

Populate an ArrayList of Character data (the wrapper class), with each char in the String represented as a separate Character element in the ArrayList

Output each Character to the command line, each on a separate line

User Ausgeorge
by
8.7k points

1 Answer

4 votes

Answer:

See the explanation section

Step-by-step explanation:

import java.util.*;

//The above statement is to import the Scanner and ArrayList class

public class StringSlicer {

public static void main(String args[]) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter your string: ");

String inputString = scan.nextLine();

ArrayList<Character> stringList = new ArrayList<Character>();

for(int i = 0; i < inputString.length(); i++){

stringList.add(inputString.charAt(i));

}

for(Character letter: stringList){

System.out.println(letter);

}

}

}

User Mohamed Nageh
by
9.0k points