Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Program 21
- Lies, Damned Lies, and Statistics
- Due 4/21/19
- */
- import javax.swing.*;
- import java.util.*;
- public class Program21{
- public static void main(String[] args){
- String nSentence = "";
- nSentence = JOptionPane.showInputDialog("Please enter a Sentence");
- System.out.println(nSentence);
- char[] aSentence = new char[nSentence.length()];
- ArrayList<String> brandNewSentence = new ArrayList<String>();
- String word = "";
- String space = " ";
- for (int i = 0; i < nSentence.length() ; i++){
- aSentence[i] = nSentence.charAt(i);
- if(aSentence[i] != ' ' ){
- word = word + aSentence[i];
- System.out.println("||" + word);
- }else if(aSentence[i] == ' '){
- if(i == 0 ){
- brandNewSentence.add(space);
- }else
- if(aSentence[i-1] != ' '){
- brandNewSentence.add(word);
- brandNewSentence.add(space);
- word = "";
- }
- } if(i == nSentence.length() - 1 && !(word.equals("")) ){
- brandNewSentence.add(word);
- }
- }
- System.out.println(brandNewSentence);
- /*
- for (int i = 0; i < aSentence.length - 1; i++){
- System.out.println(aSentence[i]);
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement